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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions apps/api/src/app/bridge/usecases/sync/sync.usecase.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import { BadRequestException, HttpException, Injectable } from '@nestjs/common';

import {
EnvironmentRepository,
Expand Down Expand Up @@ -56,8 +56,12 @@ export class Sync {
retriesLimit: 1,
workflowOrigin: WorkflowOriginEnum.EXTERNAL,
})) as DiscoverOutput;
} catch (error: any) {
throw new BadRequestException(`Bridge URL is not valid. ${error.message}`);
} catch (error) {
if (error instanceof HttpException) {
throw new BadRequestException(error.message);
}

Copy link
Collaborator 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.

throw error;
}

if (!discover) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,23 @@ export class ExecuteBridgeJob {
let raw: { retryCount?: number; statusCode?: number; message: string; url?: string };

if (error.response) {
let rawMessage: Record<string, unknown>;
const errorResponseBody = error?.response?.body;
try {
rawMessage = JSON.parse(errorResponseBody);
} catch {
Logger.error(`Unexpected body received from Bridge: ${errorResponseBody}`, LOG_CONTEXT);
rawMessage = {
error: `Unexpected body received from Bridge: ${errorResponseBody}`,
};
}

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

};
} else if (error.message) {
raw = {
Expand Down
Loading
Loading