mirror of
https://github.com/graphql-hive/console
synced 2026-05-24 09:38:26 +00:00
Access error.response.statusCode safely (#2133)
This commit is contained in:
parent
ce20d1cbf8
commit
ddf8d0620a
1 changed files with 13 additions and 8 deletions
|
|
@ -6,12 +6,6 @@ import * as Sentry from '@sentry/node';
|
|||
import { writeDuration } from './metrics';
|
||||
import { joinIntoSingleMessage, operationsOrder, registryOrder } from './serializer';
|
||||
|
||||
function hasResponse(error: unknown): error is {
|
||||
response: GotResponse;
|
||||
} {
|
||||
return error instanceof Error && 'response' in error;
|
||||
}
|
||||
|
||||
export interface ClickHouseConfig {
|
||||
protocol: string;
|
||||
host: string;
|
||||
|
|
@ -153,8 +147,7 @@ async function writeCsv(
|
|||
})
|
||||
.catch(error => {
|
||||
stopTimer({
|
||||
status:
|
||||
hasResponse(error) && error.response.statusCode ? error.response.statusCode : 'unknown',
|
||||
status: getStatusCodeFromError(error) ?? 'unknown',
|
||||
});
|
||||
Sentry.captureException(error, {
|
||||
level: 'error',
|
||||
|
|
@ -173,3 +166,15 @@ async function writeCsv(
|
|||
return Promise.reject(error);
|
||||
});
|
||||
}
|
||||
|
||||
function hasResponse(error: unknown): error is {
|
||||
response: GotResponse;
|
||||
} {
|
||||
return error instanceof Error && 'response' in error && typeof error.response === 'object';
|
||||
}
|
||||
|
||||
function getStatusCodeFromError(error: unknown) {
|
||||
if (hasResponse(error)) {
|
||||
return error.response?.statusCode;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue