Skip to content

Commit

Permalink
fix(application-generic): Bump got
Browse files Browse the repository at this point in the history
Update Got to its latest version to get all fixes and use its timing reporting so as to investigate timeouts with Bridge endpoints
  • Loading branch information
SokratisVidros committed Dec 30, 2024
1 parent 9c65e66 commit c2feabd
Show file tree
Hide file tree
Showing 5 changed files with 807 additions and 799 deletions.
8 changes: 2 additions & 6 deletions libs/application-generic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
"build": "run-p build:*",
"build:main": "tsc -p tsconfig.json",
"build:copy-template": "cpx \"src/**/*.handlebars\" build/main",
"fix": "run-s fix:*",
"fix:prettier": "prettier \"src/**/*.ts\" --write",
"lint:fix": "eslint src --fix",
"lint": "eslint src",

"watch:build": "tsc -p tsconfig.json -w",
"watch:test": "jest src --watch",
"reset-hard": "git clean -dfx && git reset --hard && pnpm install"
Expand Down Expand Up @@ -75,7 +72,7 @@
"class-transformer": "0.5.1",
"class-validator": "0.14.1",
"date-fns": "^2.29.2",
"got": "^11.8.6",
"got": "^14.4.5",
"handlebars": "^4.7.7",
"i18next": "^23.7.6",
"ioredis": "^5.2.4",
Expand Down Expand Up @@ -106,7 +103,6 @@
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@types/got": "^9.6.12",
"@types/jest": "29.5.2",
"@types/newrelic": "^9.14.6",
"@types/sanitize-html": "^2.11.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import got, {
CacheError,
HTTPError,
MaxRedirectsError,
OptionsOfTextResponseBody,
OptionsOfJSONResponseBody,
ParseError,
ReadError,
RequestError,
TimeoutError,
UnsupportedProtocolError,
UploadError,
} from 'got';
import { createHmac } from 'node:crypto';
Expand Down Expand Up @@ -140,8 +139,10 @@ export class ExecuteBridgeRequest {
});

const url = bridgeActionUrl.toString();
const options: OptionsOfTextResponseBody = {
timeout: DEFAULT_TIMEOUT,
const options: OptionsOfJSONResponseBody = {
timeout: {
request: DEFAULT_TIMEOUT
},
json: command.event,
retry: {
calculateDelay: ({ attemptCount, computedValue }) => {
Expand Down Expand Up @@ -181,12 +182,15 @@ export class ExecuteBridgeRequest {

const headers = await this.buildRequestHeaders(command);

Logger.log(`Making bridge request to \`${url}\``, LOG_CONTEXT);
try {
return await request(url, {
const res = await request(url, {
...options,
headers,
}).json();
});

Check failure

Code scanning / CodeQL

Server-side request forgery Critical

The
URL
of this request depends on a
user-provided value
.
The
URL
of this request depends on a
user-provided value
.
The
URL
of this request depends on a
user-provided value
.
The
URL
of this request depends on a
user-provided value
.
The
URL
of this request depends on a
user-provided value
.

Logger.log(`Bridge request to \`${url}\``, {timings: res.timings}, LOG_CONTEXT);

return res.body as ExecuteBridgeRequestDto<T>;
} catch (error) {
await this.handleResponseError(error, bridgeUrl, command.processError);
}
Expand Down Expand Up @@ -322,22 +326,21 @@ export class ExecuteBridgeRequest {
statusCode: error.response.statusCode,
};
} else if (error instanceof TimeoutError) {
Logger.error(`Bridge request timeout for \`${url}\``, LOG_CONTEXT);
error.response?.timings;
Logger.error(
`Bridge request timeout for \`${url}\``,
error.response.timings,
LOG_CONTEXT
);
bridgeErrorData = {
code: BRIDGE_EXECUTION_ERROR.BRIDGE_REQUEST_TIMEOUT.code,
message: BRIDGE_EXECUTION_ERROR.BRIDGE_REQUEST_TIMEOUT.message(url),
statusCode: HttpStatus.REQUEST_TIMEOUT,
};
} else if (error instanceof UnsupportedProtocolError) {
Logger.error(`Unsupported protocol for \`${url}\``, LOG_CONTEXT);
bridgeErrorData = {
code: BRIDGE_EXECUTION_ERROR.UNSUPPORTED_PROTOCOL.code,
message: BRIDGE_EXECUTION_ERROR.UNSUPPORTED_PROTOCOL.message(url),
statusCode: HttpStatus.BAD_REQUEST,
};
} else if (error instanceof ReadError) {
Logger.error(
`Response body could not be read for \`${url}\``,
error.response.timings,
LOG_CONTEXT,
);
bridgeErrorData = {
Expand Down
3 changes: 2 additions & 1 deletion libs/application-generic/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"strictNullChecks": false,
"allowSyntheticDefaultImports": true,
"outDir": "build/main",
"module": "commonjs",
"module": "ES2020",
"moduleResolution": "bundler",
"target": "es6",
"esModuleInterop": true,
"rootDir": "src",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# package.json is formatted by package managers, so we ignore it here
package.json
package.json
Loading

0 comments on commit c2feabd

Please sign in to comment.