Skip to content

Commit

Permalink
Improved: promise rejection in case of error for showing error on log…
Browse files Browse the repository at this point in the history
…in UI
  • Loading branch information
k2maan committed Nov 7, 2023
1 parent 290a8bf commit 1476475
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
8 changes: 8 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"Are you sure you have received the purchase order for the selected items? Once closed, the shipments for the selected items wont be available for receiving later.": "Are you sure you have received the purchase order for the selected items? { space } Once closed, the shipments for the selected items won't be available for receiving later.",
"Are you sure you want to change the time zone to?": "Are you sure you want to change the time zone to {timeZoneId}?",
"Arrival date": "Arrival date",
"Back to Launchpad": "Back to Launchpad",
"Cancel": "Cancel",
"Change": "Change",
"Choosing a product identifier allows you to view products with your preferred identifiers.": "Choosing a product identifier allows you to view products with your preferred identifiers.",
Expand All @@ -21,6 +22,8 @@
"Close purchase order items": "Close purchase order items",
"eCom Store": "eCom Store",
"Enter a custom date time format that you want to use when uploading documents to HotWax Commerce.": "Enter a custom date time format that you want to use when uploading documents to HotWax Commerce.",
"Error getting preferred product store.": "Error getting preferred product store.",
"Error getting user profile.": "Error getting user profile.",
"External ID": "External ID",
"Facility": "Facility",
"Location": "Location",
Expand All @@ -41,6 +44,7 @@
"Load more purchase order": "Load more purchase order",
"Loading": "Loading",
"Login": "Login",
"Login failed": "Login failed",
"Logging in": "Logging in",
"Logging out": "Logging out",
"Logout": "Logout",
Expand Down Expand Up @@ -68,6 +72,7 @@
"Purchase Order Details": "Purchase Order Details",
"Purchase Orders": "Purchase Orders",
"Qty": "Qty",
"Reason:": "Reason:",
"Receive": "Receive",
"Receive All": "Receive All",
"Receive And Close": "Receive And Close",
Expand Down Expand Up @@ -107,6 +112,7 @@
"Shipped": "Shipped",
"Shop eCommerce": "Shop eCommerce",
"Something went wrong": "Something went wrong",
"Something went wrong while getting complete user permissions.": "Something went wrong while getting complete user permissions.",
"Something went wrong while login. Please contact administrator": "Something went wrong while login. Please contact administrator.",
"Sorry, your username or password is incorrect. Please try again.": "Sorry, your username or password is incorrect. Please try again.",
"Specify which facility you want to operate from. Order, inventory and other configuration data will be specific to the facility you select.": "Specify which facility you want to operate from. Order, inventory and other configuration data will be specific to the facility you select.",
Expand All @@ -123,6 +129,8 @@
"To close the purchase order, select all.": "To close the purchase order, select all.",
"Unable to update product identifier preference": "Unable to update product identifier preference",
"Update time zone": "Update time zone",
"User is not associated with any facilities.": "User is not associated with any facilities.",
"User is not associated with any product stores.": "User is not associated with any product stores.",
"Username": "Username",
"You do not have permission to access this page": "You do not have permission to access this page",
"ZeroQuantity": "ZeroQuantity"
Expand Down
4 changes: 2 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { showToast } from '@/utils'
import { translate } from '@/i18n'

import 'vue-router'
import { Login, useAuthStore } from '@hotwax/dxp-components';
import { DxpLogin, useAuthStore } from '@hotwax/dxp-components';
import { loader } from '@/user-utils';

// Defining types for the meta values
Expand Down Expand Up @@ -71,7 +71,7 @@ const routes: Array<RouteRecordRaw> = [
{
path: '/login',
name: 'Login',
component: Login,
component: DxpLogin,
beforeEnter: loginGuard
},
{
Expand Down
18 changes: 9 additions & 9 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const getUserProfile = async (token: any): Promise<any> => {
'Content-Type': 'application/json'
}
});
if(hasError(resp)) return Promise.reject("Error getting user profile: " + JSON.stringify(resp.data));
if(resp.data.facilities.length === 0) return Promise.reject("User is not associated with any facilities: " + JSON.stringify(resp.data));
if (hasError(resp)) return Promise.reject({ message: "Error getting user profile." });
if (resp.data.facilities.length === 0) return Promise.reject({ message: "User is not associated with any facilities." });
return Promise.resolve(resp.data)
} catch(error: any) {
return Promise.reject(error)
Expand Down Expand Up @@ -91,7 +91,7 @@ const getEComStores = async (token: any, facilityId: any): Promise<any> => {
});
// Disallow login if the user is not associated with any product store
if (hasError(resp) || resp.data.docs.length === 0) {
return Promise.reject(resp.data);
return Promise.reject({ message: "User is not associated with any product stores." });
} else {
return Promise.resolve(resp.data.docs);
}
Expand Down Expand Up @@ -124,7 +124,7 @@ const getPreferredStore = async (token: any): Promise<any> => {
}
});
if (hasError(resp)) {
return Promise.reject(resp.data);
return Promise.reject({ message: "Error getting preferred product store." });
}
return Promise.resolve(resp.data.userPrefValue);
} catch(error: any) {
Expand Down Expand Up @@ -210,11 +210,11 @@ const getUserPermissions = async (payload: any, token: any): Promise<any> => {
'Content-Type': 'application/json'
}
})
if(!hasError(response)){
if (!hasError(response)) {
return Promise.resolve(response);
} else {
return Promise.reject(response);
}
} else {
return Promise.reject({ message: "Something went wrong while getting complete user permissions." });
}
}))
const permissionResponses = {
success: [],
Expand All @@ -238,7 +238,7 @@ const getUserPermissions = async (payload: any, token: any): Promise<any> => {
// Show toast to user intimiting about the failure
// Allow user to login
// TODO Implement Retry or improve experience with show in progress icon and allowing login only if all the data related to user profile is fetched.
if (permissionResponses.failed.length > 0) Promise.reject("Something went wrong while getting complete user permissions.");
if (permissionResponses.failed.length > 0) Promise.reject({ message: "Something went wrong while getting complete user permissions." });
}
}
return serverPermissions;
Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const actions: ActionTree<UserState, RootState> = {
const permissionError = 'You do not have permission to access the app.';
showToast(translate(permissionError));
console.error("error", permissionError);
return Promise.reject(new Error(permissionError));
return Promise.reject({ message: permissionError });
}
}

Expand Down Expand Up @@ -97,7 +97,7 @@ const actions: ActionTree<UserState, RootState> = {
// TODO Check if handling of specific status codes is required.
showToast(translate('Something went wrong while login. Please contact administrator'));
console.error("error", err);
return Promise.reject(new Error(err))
return Promise.reject(err)
}
},

Expand Down

0 comments on commit 1476475

Please sign in to comment.