mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
02a4da9ad2
* Fixes #12145 When transactions fail, preserve error message when presented with an error object. Fallback to stringified error for other cases. * Perserve error stack when err.stack is present, else set stack to message. * Use optional chaining
23 lines
541 B
JavaScript
23 lines
541 B
JavaScript
/**
|
|
* Returns error without stack trace for better UI display
|
|
* @param {Error} err - error
|
|
* @returns {Error} Error with clean stack trace.
|
|
*/
|
|
export default function cleanErrorStack(err) {
|
|
let { name } = err;
|
|
name = name === undefined ? 'Error' : String(name);
|
|
|
|
let msg = err.message;
|
|
msg = msg === undefined ? '' : String(msg);
|
|
|
|
if (name === '') {
|
|
err.stack = err.message;
|
|
} else if (msg === '') {
|
|
err.stack = err.name;
|
|
} else if (!err.stack) {
|
|
err.stack = `${err.name}: ${err.message}`;
|
|
}
|
|
|
|
return err;
|
|
}
|