0

Is there a possibility how to overwrite those temporary error messages that are displayed when an error occured? For example, when there is an error with 500 status, the front-end displays an error: Internal Server Error. I would like to check if the error has a status of 500 and then to overwrite the message to something more specific. So far I have tried to put this code into my AuthProvider.js but it does not seem to work for me.

if (type === AUTH_ERROR) {
  const status = params.status;
  if (status === 500) {
    throw new Error('ErrorMessage');
  }
  return Promise.resolve();
}

I checked the value of status and it is 500. but the message stays the same.

Any ideas how to solve this?

Thank you in advance.

AdamSulc
  • 330
  • 2
  • 4
  • 19

1 Answers1

0

If your purpose is to observe precise message in console log, you can do something as below:

{
    console.error('Auth failed');
}

Since you clarified that I assumed your purpose wrongly, below is the code to fulfill your request of throwing customized error:

function CommonException(message, code)
{
    this.message = message;
    this.code = code;
}

try
{
    var exception = new CommonException('ErrorMessage', 500);

    throw exception;

    alert('Whatever');
}
catch (e) {
    alert(e.message);
    alert(e.code)
}
W.X.
  • 81
  • 3
  • No. I would like to check if the error has a status of 500 and then to overwrite the message to something more specific. That is what I want to achieve, not to `console.log` variables or strings. – AdamSulc Jul 22 '19 at 08:49
  • Besides, if you mean you only want to extend Error, please check with this answer: https://stackoverflow.com/questions/31089801/extending-error-in-javascript-with-es6-syntax-babel – W.X. Jul 22 '19 at 09:30