From cb1fe59a2edbe56ebc009f7a1a209123ae585189 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <p.gawron@atcomp.pl>
Date: Wed, 2 Oct 2024 14:16:49 +0200
Subject: [PATCH] don't send report when there is a problem with connectivity

---
 CHANGELOG                                          |  2 ++
 src/redux/middlewares/error.middleware.ts          | 14 ++++++++++++++
 .../getErrorMessage/getErrorMessage.constants.ts   |  1 +
 3 files changed, 17 insertions(+)

diff --git a/CHANGELOG b/CHANGELOG
index 9352e2ec..0399b142 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,6 @@
 minerva-front (18.0.0~beta.4) stable; urgency=medium
+  * Bugfix: connectivity issue should report a problem with network instead of
+    submitting error report(#293)
   * Bugfix: source map for js was missing (#292)
   * Bugfix: sometimes project don't have link to disease or organism, this
     crashed listing of projects after log in (#290)
diff --git a/src/redux/middlewares/error.middleware.ts b/src/redux/middlewares/error.middleware.ts
index 56ba18c0..0a8913b5 100644
--- a/src/redux/middlewares/error.middleware.ts
+++ b/src/redux/middlewares/error.middleware.ts
@@ -3,6 +3,9 @@ import { Action, createListenerMiddleware, isRejected } from '@reduxjs/toolkit';
 import { createErrorData } from '@/utils/error-report/errorReporting';
 import { openAccessDeniedModal, openErrorReportModal } from '@/redux/modal/modal.slice';
 import { getProjects } from '@/redux/projects/projects.thunks';
+import axios from 'axios';
+import { AXIOS_ERROR_NETWORK } from '@/utils/getErrorMessage/getErrorMessage.constants';
+import { showToast } from '@/utils/showToast';
 
 export const errorListenerMiddleware = createListenerMiddleware();
 
@@ -16,6 +19,17 @@ export const errorMiddlewareListener = async (
     if (action.error.code === '403') {
       dispatch(getProjects());
       dispatch(openAccessDeniedModal());
+    } else if (axios.isAxiosError(action.error) && action.error.code === AXIOS_ERROR_NETWORK) {
+      // eslint-disable-next-line no-console
+      console.log(action.error);
+      showToast({
+        type: 'error',
+        message:
+          'There was a problem with fetching data from minerva server. ' +
+          'Please check your internet connection and try again. ' +
+          'If problem problem persists contact system administrator.',
+        duration: 15000,
+      });
     } else {
       const errorData = await createErrorData(action.error, getState());
       dispatch(openErrorReportModal(errorData));
diff --git a/src/utils/getErrorMessage/getErrorMessage.constants.ts b/src/utils/getErrorMessage/getErrorMessage.constants.ts
index e6d05b27..3f9fa192 100644
--- a/src/utils/getErrorMessage/getErrorMessage.constants.ts
+++ b/src/utils/getErrorMessage/getErrorMessage.constants.ts
@@ -2,6 +2,7 @@ export const UNKNOWN_ERROR = 'An unknown error occurred. Please try again later.
 export const UNKNOWN_AXIOS_ERROR_CODE = 'UNKNOWN_AXIOS_ERROR';
 export const NOT_FOUND_AXIOS_ERROR_CODE = '404';
 export const GENERIC_AXIOS_ERROR_CODE = 'ERR_BAD_REQUEST';
+export const AXIOS_ERROR_NETWORK = 'ERR_NETWORK';
 
 export const HTTP_ERROR_MESSAGES = {
   400: "The server couldn't understand your request. Please check your input and try again.",
-- 
GitLab