-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make displayed Web errors more meaningful #92553
Make displayed Web errors more meaningful #92553
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Nicely spotted!
Are we ok with "??" https://caniuse.com/?search=%3F%3F Without need for function displayFailureNotice(err) {
console.error(err);
setStatusNotice(err.message ?? err);
setStatusMode('notice');
initializing = false;
} will it make a difference? setStatusNotice(err.message || err); 💣 EDIT: |
Indeed, I missed that, what's the rationale for chaining to |
|
8503f90
to
c13d578
Compare
Ah yes, const err = { message: "" };
const msg = err.message ?? err;
console.log(msg); // Outputs: "" and const err = { message: "" };
const msg = err.message || err;
console.log(msg); // Outputs: { message: "" } |
e3583a4
to
87a6a9f
Compare
@patwork @Faless I updated my code finally, to make sure that function displayFailureNotice(err) {
console.error(err);
if (err instanceof Error) {
setStatusNotice(err.message);
} else if (typeof err === 'string') {
setStatusNotice(err);
} else if (typeof err === 'object' && typeof err.toString === 'function') {
setStatusNotice(err.toString());
} else {
setStatusNotice('An unknown error occured');
}
setStatusMode('notice');
initializing = false;
} |
87a6a9f
to
1dec67b
Compare
I guess we can assume that This could potentially get us "[Object Object]" or similiar: } else if (typeof err === 'object' && typeof err.toString === 'function') {
setStatusNotice(err.toString()); It is better to write right away that it is an unknown error.
|
1dec67b
to
2c3b871
Compare
Thanks! |
Updates the code to display an error to not only show the message, but the context as well.