-
Notifications
You must be signed in to change notification settings - Fork 20
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
Errors stop getting sent to client if the override of fetch includes a catch callback #146
Comments
Fixed it by removing the catch callback and overriding
I think it should be added to the docs in #145. As also logging unsuccessful requests is a possible common use case if one wants to log the successful ones. At the same time I'm not entirely sure why catching fetch breaks the response to the client. I guess it happens because catching fetch directly bypasses |
@AlphaSteam I think it's a good suggestion to add the error handling case to my PR as well. The reason that breaks is because you're suppressing the error by catching it. If you'd like to handle the error in a catch you need to rethrow it at the end of the catch block. If you just want to observe the error / do some logging, you can use the datasource-rest/src/RESTDataSource.ts Lines 533 to 536 in c9ffa7f
I think what you're doing is fine with |
I was overriding the fetch method to replicate the functionality I had with
didReceiveResponse
, which is logging each request. For that I need to be able to differentiate and log both successful and unsuccessful requests.Using the fix in #109 let's me log the successful requests.
The problem arises when trying to log the unsuccessful ones. I tried adding a catch callback as follows:
return super.fetch<TResult>(path, incomingRequest).then(onFulfilled).catch(onRejected);
The function
onRejected
is:incomingRequest
andurl
come from fetch.This logs the unsuccessful requests, but makes it so the client stops receiving error information. Without the catch, apollo server returns this response:
With it, it responds with:
The text was updated successfully, but these errors were encountered: