Skip to content

Commit 41e3f2d

Browse files
authored
add error reason (#241)
* add error reason * fix lint * fix formatting
1 parent 80b00bb commit 41e3f2d

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ Any errors originating from Node.js will be passed on and we use [GOT](https://g
418418

419419
- `code` (`string`) - [The Transloadit API error code](https://transloadit.com/docs/api/response-codes/#error-codes).
420420
- `rawMessage` (`string`) - A textual representation of the Transloadit API error.
421+
- `reason` (`string`) - Additional information about the Transloadit API error.
421422
- `assemblyId`: (`string`) - If the request is related to an assembly, this will be the ID of the assembly.
422423
- `assemblySslUrl` (`string`) - If the request is related to an assembly, this will be the SSL URL to the assembly .
423424

src/ApiError.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { HTTPError, RequestError } from 'got'
33
export interface TransloaditErrorResponseBody {
44
error?: string
55
message?: string
6+
reason?: string
67
assembly_ssl_url?: string
78
assembly_id?: string
89
}
@@ -16,6 +17,8 @@ export class ApiError extends Error {
1617

1718
rawMessage?: string
1819

20+
reason?: string
21+
1922
assemblySslUrl?: string
2023

2124
assemblyId?: string
@@ -36,6 +39,7 @@ export class ApiError extends Error {
3639

3740
super(message)
3841
this.rawMessage = body.message
42+
this.reason = body.reason
3943
this.assemblyId = body.assembly_id
4044
this.assemblySslUrl = body.assembly_ssl_url
4145
this.code = body.error

test/unit/mock-http.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,18 @@ describe('Mocked API tests', () => {
115115
it('should throw error with error code', async () => {
116116
const client = getLocalClient()
117117

118-
nock('http://localhost')
119-
.post(createAssemblyRegex)
120-
.reply(400, { error: 'INVALID_FILE_META_DATA', message: 'Invalid file metadata' })
118+
nock('http://localhost').post(createAssemblyRegex).reply(400, {
119+
error: 'INVALID_FILE_META_DATA',
120+
message: 'Invalid file metadata',
121+
reason: 'Some reason',
122+
})
121123

122124
await expect(client.createAssembly()).rejects.toThrow(
123125
expect.objectContaining<ApiError>({
124126
name: 'ApiError',
125127
code: 'INVALID_FILE_META_DATA',
126128
rawMessage: 'Invalid file metadata',
129+
reason: 'Some reason',
127130
message: 'API error (HTTP 400) INVALID_FILE_META_DATA: Invalid file metadata',
128131
})
129132
)
@@ -165,6 +168,7 @@ describe('Mocked API tests', () => {
165168
expect.stringMatching(` at .+`),
166169
expect.stringMatching(` code: 'INVALID_FILE_META_DATA',`),
167170
expect.stringMatching(` rawMessage: 'Invalid file metadata',`),
171+
expect.stringMatching(` reason: undefined,`),
168172
expect.stringMatching(
169173
` assemblySslUrl: 'https:\\/\\/api2-oltu\\.transloadit\\.com\\/assemblies\\/foo'`
170174
),

0 commit comments

Comments
 (0)