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

feat(api, worker, application-generic): Add exhaustive error handling for bridge requests #6715

Merged

Conversation

rifont
Copy link
Contributor

@rifont rifont commented Oct 17, 2024

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 type
  • All Node.js Network error code (ref)

Screenshots

Expand for optional sections

Related enterprise PR

Special notes for your reviewer

Copy link

linear bot commented Oct 17, 2024

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 } : {}),
Copy link
Contributor Author

@rifont rifont Oct 17, 2024

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..."

Copy link

netlify bot commented Oct 17, 2024

Deploy Preview for novu-stg-vite-dashboard-poc ready!

Name Link
🔨 Latest commit d0f7987
🔍 Latest deploy log https://app.netlify.com/sites/novu-stg-vite-dashboard-poc/deploys/6711208f676f400008cd8e40
😎 Deploy Preview https://deploy-preview-6715--novu-stg-vite-dashboard-poc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

environmentBridgeUrl,
),
});
}
Copy link
Contributor Author

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);
}
Copy link
Contributor Author

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,
}),
);
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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)

Copy link
Contributor Author

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, {
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@rifont rifont merged commit e058fa4 into next Oct 17, 2024
30 checks passed
@rifont rifont deleted the nv-4502-add-exhaustive-error-handling-for-bridge-requests branch October 17, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants