Skip to content
Discussion options

You must be logged in to vote

The code looks correct, you should be able to do something like this:

setMessage(error.data.message);

You're returning the error info as json, then it's being set to error.data here:

const data = await response.json();

if (response.ok) {
  return data;
}

// This shows the 401 unauthorized response without the error I sent in the api/login page
console.log('fetcher', response);
const error = new Error(response.statusText);
error.response = response;
error.data = data;

If your custom error was thrown, then the error data is in error.data.

error.message would be response.statusText, which in the case of your custom error won't have anything important.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@NotNotRama
Comment options

Answer selected by NotNotRama
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants