Skip to content

Commit

Permalink
Improved: Promise response on api failure
Browse files Browse the repository at this point in the history
  • Loading branch information
amansinghbais committed Feb 14, 2024
1 parent ecb79ae commit aab0fab
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 12 deletions.
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
36 changes: 30 additions & 6 deletions src/modules/user/index.ts
Original file line number Diff line number Diff line change
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 @@ -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

0 comments on commit aab0fab

Please sign in to comment.