2023-06-20 00:43:36 +05:30
|
|
|
/**
|
|
|
|
* Utility to parse an error object returned from API.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param { Object } error - An error object directly from API response
|
|
|
|
* @param { string } error.message - The error message, returned from API.
|
|
|
|
* @param { string } defaultMessage - Default user-facing error message
|
|
|
|
* @returns { string } - A transformed user-facing error message, or defaultMessage
|
|
|
|
*/
|
|
|
|
export const parseErrorMessage = (error = {}, defaultMessage = '') => {
|
|
|
|
const messageString = error.message || '';
|
|
|
|
return messageString.startsWith(window.gon.uf_error_prefix)
|
|
|
|
? messageString.replace(window.gon.uf_error_prefix, '').trim()
|
|
|
|
: defaultMessage;
|
2023-05-27 22:25:52 +05:30
|
|
|
};
|