-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(api, worker, application-generic): Add exhaustive error handling for bridge requests #6715
feat(api, worker, application-generic): Add exhaustive error handling for bridge requests #6715
Conversation
raw = { | ||
url: statelessBridgeUrl, | ||
statusCode: error.response?.statusCode, | ||
message: error.response?.statusMessage, | ||
...(error.response?.retryCount ? { retryCount: error.response?.retryCount } : {}), | ||
...(error?.response?.body?.length > 0 ? { raw: JSON.parse(error?.response?.body) } : {}), | ||
...(error?.response?.body?.length > 0 ? { raw: rawMessage } : {}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this lack of error handling during body parsing was contributing to execution detail logs not surfacing due to an inability to parse the error body. This was observed with errors such as "BSON circular value cannot be converted..."
✅ Deploy Preview for novu-stg-vite-dashboard-poc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
environmentBridgeUrl, | ||
), | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throw an exception here explicitly if trying to request to an external Bridge URL when it doesn't exist on the environment.
} catch (error) { | ||
if (error instanceof HttpException) { | ||
throw new BadRequestException(error.message); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplifying the error thrown here.
Let non-HTTP exceptions bubble up to the API exception handler.
GetDecryptedSecretKeyCommand.create({ | ||
environmentId: command.environmentId, | ||
}), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactoring many of these to discrete methods to make the execute
method easier to read.
@@ -152,75 +147,38 @@ export class ExecuteBridgeRequest { | |||
headers, | |||
}).json(); | |||
} catch (error) { | |||
if (error instanceof RequestError) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to a discrete handler for errors.
@@ -272,4 +241,135 @@ export class ExecuteBridgeRequest { | |||
|
|||
return apiUrl; | |||
} | |||
|
|||
private handleResponseError(error: unknown, url: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exhaustive error handling added for all of:
got
package error codes (it does a good job of handling these with explicit classes per error type- All Node.js error code (ref)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All thrown error messages now include the URL to support client debugging.
} from '@nestjs/common'; | ||
import got, { OptionsOfTextResponseBody, RequestError } from 'got'; | ||
import got, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the era of fetch, do we need to rely on got
? Got by default gives us retries which I am not very sure if it's a great idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will tackle this offline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elaborating a little, is the thinking that we should handle retries elsewhere? At the queue layer, for example?
I tend to agree, the value we're getting from retries in practice is minimal, especially considering the total retry duration after incorporating backoff is less than 1 minute. It's unlikely an external bridge endpoint would recover from a total network fault within that timespan.
What changed? Why was the change needed?
Add exhaustive error handling during Bridge requests for all of:
got
package error codes (it does a good job of handling these with explicit classes per error typeScreenshots
Expand for optional sections
Related enterprise PR
Special notes for your reviewer