debian-mirror-gitlab/app/assets/javascripts/lib/utils/error_message.js
2023-06-20 00:43:36 +05:30

15 lines
643 B
JavaScript

/**
* 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;
};