Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved: error message in case of api fail resulting in reject Promise (dxp-258) #79

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions src/modules/notification/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ async function getNotificationEnumIds(enumTypeId: string): Promise<any> {
throw resp.data;
}
} catch (err) {
return Promise.reject(err)
return Promise.reject({
code: 'error',
message: 'Something went wrong',
serverResponse: err
})
}
}

Expand Down Expand Up @@ -52,7 +56,11 @@ async function getNotificationUserPrefTypeIds(applicationId: string, userLoginId
throw resp.data;
}
} catch (err) {
return Promise.reject(err)
return Promise.reject({
code: 'error',
message: 'Something went wrong',
serverResponse: err
})
}
}

Expand All @@ -76,7 +84,11 @@ async function storeClientRegistrationToken(registrationToken: string, deviceId:
throw resp.data;
}
} catch (err) {
return Promise.reject(err)
return Promise.reject({
code: 'error',
message: 'Something went wrong',
serverResponse: err
})
}
}

Expand All @@ -100,7 +112,11 @@ async function removeClientRegistrationToken(deviceId: string, applicationId: st
throw resp.data;
}
} catch (err) {
return Promise.reject(err)
return Promise.reject({
code: 'error',
message: 'Something went wrong',
serverResponse: err
})
}
}

Expand All @@ -123,7 +139,11 @@ async function subscribeTopic(topicName: string, applicationId: string): Promise
throw resp.data;
}
} catch (err) {
return Promise.reject(err)
return Promise.reject({
code: 'error',
message: 'Something went wrong',
serverResponse: err
})
}
}

Expand All @@ -146,7 +166,11 @@ async function unsubscribeTopic(topicName: string, applicationId: string): Promi
throw resp.data;
}
} catch (err) {
return Promise.reject(err)
return Promise.reject({
code: 'error',
message: 'Something went wrong',
serverResponse: err
})
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/modules/order/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function getOrderDetails (orderId: string): Promise<Order | Respons
url: 'solr-query',
method: 'get',
params: payload
})
}) as any

if (resp?.status == 200 && !hasError(resp) && resp.data?.grouped?.orderId?.groups?.length > 0) {
const group = resp.data.grouped.orderId.groups[0]
Expand Down Expand Up @@ -56,7 +56,7 @@ export async function getOrderDetails (orderId: string): Promise<Order | Respons
return Promise.reject({
code: 'error',
message: `Unable to fetch order details for orderId: ${orderId}`,
serverResponse: resp
serverResponse: resp.data
})
}
} catch (err) {
Expand All @@ -75,7 +75,7 @@ export async function updateOrderStatus (payload: {orderId: string, statusId: st
url: '/service/changeOrderStatus',
method: 'post',
data: payload
})
}) as any

if (resp?.status == 200 && !hasError(resp)) {
return Promise.resolve({
Expand All @@ -87,7 +87,7 @@ export async function updateOrderStatus (payload: {orderId: string, statusId: st
return Promise.reject({
code: 'error',
message: 'Unable to update order status',
serverResponse: resp
serverResponse: resp.data
})
}
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/stock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function fetchProductsStockAtFacility(productIds: Array<string>, facilityI
return Promise.reject({
code: "error",
message: "Unable to find the stock for products",
serverResponse: ""
serverResponse: resp.data
})
}
} catch(err) {
Expand Down Expand Up @@ -84,7 +84,7 @@ async function fetchProductsStock(productIds: Array<string>): Promise<Array<Stoc
return Promise.reject({
code: "error",
message: "Unable to find the stock for products",
serverResponse: ""
serverResponse: resp.data
})
}
} catch(err) {
Expand Down
44 changes: 34 additions & 10 deletions src/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ async function getProfile(): Promise<User | Response> {
} else {
return Promise.reject({
code: 'error',
message: 'Something went wrong',
serverResponse: 'Failed to fetch user profile information'
message: 'Failed to fetch user profile information',
serverResponse: resp.data
})
}
} catch(err) {
Expand Down Expand Up @@ -82,10 +82,18 @@ async function setProductIdentificationPref(eComStoreId: string, productIdentifi
if(!hasError(resp)) {
return Promise.resolve(productIdentificationPref)
} else {
return Promise.reject(resp)
return Promise.reject({
code: 'error',
message: 'Failed to set product identification pref',
serverResponse: resp.data
})
}
} catch(err) {
return Promise.reject(err)
return Promise.reject({
code: 'error',
message: 'Something went wrong',
serverResponse: err
})
}
}

Expand Down Expand Up @@ -171,7 +179,11 @@ async function logout(): Promise<any> {

return Promise.resolve(resp.data)
} catch(err) {
return Promise.reject(err)
return Promise.reject({
code: 'error',
message: 'Something went wrong',
serverResponse: err
})
}
}

Expand Down Expand Up @@ -219,8 +231,8 @@ async function getUserFacilities(token: any, baseURL: string, partyId: string, f
} else {
return Promise.reject({
code: 'error',
message: 'Something went wrong',
serverResponse: 'Failed to fetch user facilities'
message: 'Failed to fetch user facilities',
serverResponse: resp.data
})
}
} catch(error: any) {
Expand Down Expand Up @@ -250,7 +262,11 @@ async function getUserPreference(token: any, baseURL: string, userPrefTypeId: st
}
return Promise.resolve(resp.data.userPrefValue ? JSON.parse(resp.data.userPrefValue) : {});
} catch (err) {
return Promise.reject(err)
return Promise.reject({
code: 'error',
message: 'Something went wrong',
serverResponse: err
})
}
}

Expand All @@ -268,7 +284,11 @@ async function setUserPreference(payload: any): Promise<any> {
throw resp.data
}
} catch (err) {
return Promise.reject(err)
return Promise.reject({
code: 'error',
message: 'Something went wrong',
serverResponse: err
})
}
}

Expand All @@ -286,7 +306,11 @@ const setUserLocale = async (payload: any): Promise<any> => {
throw resp.data
}
} catch (error) {
return Promise.reject(error)
return Promise.reject({
code: 'error',
message: 'Something went wrong',
serverResponse: error
})
}
}

Expand Down
Loading