apollo-client icon indicating copy to clipboard operation
apollo-client copied to clipboard

Parse http response

Open Lana11s opened this issue 4 years ago • 5 comments

We run into issue that when server does not respond in JSON format, there will be a ServerParseError instead of the ServerError. This happens because JSON.parse() is done before checking the status code: https://github.com/apollographql/apollo-client/blob/main/src/link/http/parseAndCheckHttpResponse.ts (lines 19 and 30).

In this case, the error message of ServerParseError does not provide the information about the actual cause but only the parse error.

In some error cases, there is no guarantee that server will repsonse in JSON fromat. For example if there is an authentication error. Or if response is an uncomplete JSON object because of 500 out of memory.

Could you please check if it is intended to be this way? Thank you!

Lana11s avatar Oct 19 '21 08:10 Lana11s

@Lana11s I think you're right it would be best to check the status code before parsing the JSON. I would be happy to review a PR if you have time for that (no pressure though)!

benjamn avatar Oct 20 '21 21:10 benjamn

@benjamn I can try it. Probably it will not be within the next couple of weeks. If there is any other volunteer, it would be very appreciated.

Lana11s avatar Oct 22 '21 13:10 Lana11s

Hello! @Lana11s @benjamn I just create a PR to fix this issue, please review! #8974

TakahiroHimi avatar Oct 27 '21 08:10 TakahiroHimi

@Lana11s I noticed #8974 wasn't merged -- is there anything blocking it? I started seeing this bug, but that PR should fix it

dillontiner avatar Jul 11 '22 22:07 dillontiner

Maybe should've tagged @benjamn instead. Is there any reason not to merge the fix? Looks like a small change that just needs a rebase (PR if it helps)

dillontiner avatar Aug 08 '22 22:08 dillontiner

I would love to have this PR merge when possible. It 's a small change, but would remove a lot of "workaround" code in my project to retrieve the proper error without using the onError link (cause has noted it doesnt work in this case)

Crocsx avatar Aug 16 '22 10:08 Crocsx