khatavani-client
Version:
The Backend-Api-Integration package simplifies interaction with the backend API by providing a set of CRUD methods for common endpoints. It abstracts away the complexity of making HTTP requests and handling responses, allowing developers to focus on appli
28 lines (23 loc) • 794 B
text/typescript
export function mergeErrorMessages(responseJson: any) {
let errorMessages = undefined;
if (responseJson?.details) {
errorMessages = responseJson.details
} else if (responseJson) {
errorMessages = [responseJson]
}
let mergedMessage = undefined;
if (errorMessages) {
mergedMessage = errorMessages.map((item: any) => item.message).join(', ');
}
return mergedMessage ? mergedMessage : " Contact Admin !!!";
}
export const cloneResponse = async (res: any) => {
var temporaryValue: any = res.clone();
try {
return await res.json();
} catch (e) {
return await temporaryValue.text();
// that is for "" string or null get crash at converting the
// it to the json
}
}