Skip to content

Commit

Permalink
add extra to error
Browse files Browse the repository at this point in the history
  • Loading branch information
altaywtf committed Sep 7, 2023
1 parent fe6c886 commit a7bdc72
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface IPutioAPIClientErrorData {
error_type: string
error_message: string
status_code: number
extra: Record<string, unknown>
}

export interface IPutioAPIClientError
Expand Down
1 change: 1 addition & 0 deletions src/interceptors/response/clientIPChangeEmitter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe('interceptors/response/clientIPChangeEmitter', () => {
error_type: 'API_ERROR',
error_message: 'Putio API Error',
status_code: 400,
extra: { foo: 'bar' },
},
headers: { 'putio-client-ip': '0.0.0.0' },
status: 400,
Expand Down
1 change: 1 addition & 0 deletions src/interceptors/response/errorEmitter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('interceptors/response/errorEmitter', () => {
status_code: 400,
error_type: 'API_ERROR',
error_message: 'Putio API Error',
extra: { foo: 'bar' },
},
headers: {},
status: 400,
Expand Down
10 changes: 10 additions & 0 deletions src/interceptors/response/responseFormatter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('interceptors/response/responseFormatter', () => {
error_type: 'API_ERROR',
error_message: 'Putio API Error',
status_code: 400,
extra: { foo: 'bar' },
},
headers: {
'x-trace-id': 'MOCK_TRACE_ID',
Expand All @@ -58,6 +59,9 @@ describe('interceptors/response/responseFormatter', () => {
Object {
"error_message": "Putio API Error",
"error_type": "API_ERROR",
"extra": Object {
"foo": "bar",
},
"status_code": 400,
"x-trace-id": "MOCK_TRACE_ID",
}
Expand All @@ -84,6 +88,7 @@ describe('interceptors/response/responseFormatter', () => {
Object {
"error_message": "AXIOS_ERROR_MESSAGE",
"error_type": "ERROR",
"extra": Object {},
"status_code": 502,
"x-trace-id": undefined,
}
Expand All @@ -97,6 +102,7 @@ describe('interceptors/response/responseFormatter', () => {
Object {
"error_message": "AXIOS_ERROR_MESSAGE",
"error_type": "ERROR",
"extra": Object {},
"status_code": 0,
"x-trace-id": undefined,
}
Expand All @@ -120,6 +126,7 @@ describe('interceptors/response/responseFormatter', () => {
Object {
"error_message": "AXIOS_ERROR_MESSAGE",
"error_type": "ERROR",
"extra": Object {},
"foo": "bar",
"status_code": 400,
"x-trace-id": undefined,
Expand All @@ -144,6 +151,9 @@ describe('interceptors/response/responseFormatter', () => {
Object {
"error_message": "MOCK_MESSAGE",
"error_type": "MOCK_ERROR",
"extra": Object {
"foo": "bar",
},
"status_code": 0,
}
`),
Expand Down
1 change: 1 addition & 0 deletions src/interceptors/response/responseFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const createResponseFormatter: PutioAPIClientResponseInterceptorFactory =
error_message: error.message,
error_type: 'ERROR',
status_code: 0,
extra: {},
}

if (error.response && error.response.data) {
Expand Down
1 change: 1 addition & 0 deletions src/test-utils/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const mockPutioAPIClientError: IPutioAPIClientError = {
error_type: 'MOCK_ERROR',
error_message: 'MOCK_MESSAGE',
status_code: 0,
extra: { foo: 'bar' },
},
toJSON() {
return this.data
Expand Down

0 comments on commit a7bdc72

Please sign in to comment.