From 457bbda77c46695b3d15f5a2f755808d708f9408 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Tue, 13 Aug 2024 13:24:35 -0400 Subject: [PATCH] fix: if no response from server reject with proper payload format --- Client/src/Features/Auth/authSlice.js | 36 +++++++++++++++---- .../PageSpeedMonitor/pageSpeedMonitorSlice.js | 30 +++++++++++++--- .../UptimeMonitors/uptimeMonitorsSlice.js | 30 +++++++++++++--- 3 files changed, 80 insertions(+), 16 deletions(-) diff --git a/Client/src/Features/Auth/authSlice.js b/Client/src/Features/Auth/authSlice.js index a30c295d9..6da315fc4 100644 --- a/Client/src/Features/Auth/authSlice.js +++ b/Client/src/Features/Auth/authSlice.js @@ -20,7 +20,11 @@ export const register = createAsyncThunk( if (error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -33,7 +37,11 @@ export const login = createAsyncThunk("auth/login", async (form, thunkApi) => { if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } }); @@ -72,7 +80,11 @@ export const update = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -91,7 +103,11 @@ export const deleteUser = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -106,7 +122,11 @@ export const forgotPassword = createAsyncThunk( if (error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -128,7 +148,11 @@ export const setNewPassword = createAsyncThunk( if (error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); diff --git a/Client/src/Features/PageSpeedMonitor/pageSpeedMonitorSlice.js b/Client/src/Features/PageSpeedMonitor/pageSpeedMonitorSlice.js index 4377edb35..6af825a37 100644 --- a/Client/src/Features/PageSpeedMonitor/pageSpeedMonitorSlice.js +++ b/Client/src/Features/PageSpeedMonitor/pageSpeedMonitorSlice.js @@ -25,7 +25,11 @@ export const createPageSpeed = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -40,7 +44,11 @@ export const getPageSpeedMonitors = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -63,7 +71,11 @@ export const getPageSpeedByUserId = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -94,7 +106,11 @@ export const updatePageSpeed = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -115,7 +131,11 @@ export const deletePageSpeed = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); diff --git a/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js b/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js index e69e6d41d..27d616e1e 100644 --- a/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js +++ b/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js @@ -25,7 +25,11 @@ export const createUptimeMonitor = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -40,7 +44,11 @@ export const getUptimeMonitors = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -63,7 +71,11 @@ export const getUptimeMonitorsByUserId = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -94,7 +106,11 @@ export const updateUptimeMonitor = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -115,7 +131,11 @@ export const deleteUptimeMonitor = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } );