debian-mirror-gitlab/app/assets/javascripts/lib/utils/error_message.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

16 lines
643 B
JavaScript
Raw Normal View History

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