apollo-client
apollo-client copied to clipboard
Parse http response
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 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 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.
Hello! @Lana11s @benjamn I just create a PR to fix this issue, please review! #8974
@Lana11s I noticed #8974 wasn't merged -- is there anything blocking it? I started seeing this bug, but that PR should fix it
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)
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)