1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-02-27 06:35:49 +00:00
bramw_baserow/web-frontend/modules/database/utils/errors.js
2025-02-26 12:37:45 +00:00

23 lines
621 B
JavaScript

/**
* Returns most expected error structure.
*
* When an error is thrown, it can be of any type. This function tries to return
* the most useful error data from the error. It tries to return any first of the
* following:
*
* * http response body, if it's a DRF error structure
* * http response object
* * the error as-is in any other case
*
* @param err
* @param errorMap
* @returns {*}
*/
export function normalizeError(err) {
err = err.response?.data?.message ? err.response.data : err.response || err
return {
message: err.message,
content: err.detail,
statusCode: err.statusCode,
}
}