Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

errors mapper for server response #112

Open
jhen0409 opened this issue May 14, 2018 · 4 comments
Open

errors mapper for server response #112

jhen0409 opened this issue May 14, 2018 · 4 comments

Comments

@jhen0409
Copy link

I've realized I have no way to resolve error of server response, looks like this line ignored server error and did nothing. I expected that can be resolved to errors of GraphQL response, is this lib have any plans to support or PR welcome? 😃

@n1ru4l
Copy link
Owner

n1ru4l commented May 14, 2018

@jhen0409 Sure feel free to pitch your idea/file in a pull request. Error handling is important!

@fodier
Copy link
Contributor

fodier commented May 14, 2018

Hi,

I can’t speak for Laurin but I would welcome a PR that stops ignoring errors. In the meantime, you can provide a custom fetcher to generateRestSchema. That custom fetcher could be something like:

const fetcher = (...args) => fetch(...args).then((response) => {
  if (!response.ok) {
    throw new Error('Network Error');
  }
  return response;
});

The thrown error will appear in the GraphQL response.

@n1ru4l
Copy link
Owner

n1ru4l commented May 14, 2018

@jhen0409 @fodier We could call response.json()either way, however some API do not include a response body when sending a 500 or 404 error (#32).

We could also change the behaviour of responseMapper completely. When not declared everyting would behave like the current implementation. Otherwise the responseMapperfunction receives the raw response object returned by fetch and the user has to determine whether it is an error by returning a Promise that either resolves or rejects.

@n1ru4l
Copy link
Owner

n1ru4l commented Jun 1, 2018

@jhen0409 @fodier what do you think?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants