Skip to content
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

Handle malformed or non existent JSON in response #20

Merged
merged 1 commit into from
Oct 4, 2016

Conversation

JonathanUsername
Copy link
Contributor

Hi, we have a number of reasons why the /graphql endpoint when hit will actually return HTML/XML or something that isn't valid JSON. For instance, if the user is not authenticated then we return a 403 page, this happens at the Nginx level.

At the moment that means that we get an error coming through the middleware as a SyntaxError. This can't be gracefully dealt with by middleware other than by trying to catch that - if (error.name === 'SyntaxError') - and aside from that being ugly it also means the status code is ignored.

In this PR I'm trying to address this by catching any parsing errors arising from res.json() and returning a plain object instead. This is so that the status code can be handled correctly by thrownOnServerError where it throws the whole response, so that we can deal with the response.status inside our app (and direct the user to log in again!).

@st0ffern
Copy link

st0ffern commented Oct 1, 2016

@JonathanUsername he is on vacation and i think he will look into this when he is back 😉

@nodkz nodkz merged commit 6bc2e7a into relay-tools:master Oct 4, 2016
@nodkz
Copy link
Collaborator

nodkz commented Oct 4, 2016

@JonathanUsername thanks for PR.
Bumped version 1.3.5

PS. Sorry for delay, I was on vacation.

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

Successfully merging this pull request may close these issues.

3 participants