Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ Any errors originating from Node.js will be passed on and we use [GOT](https://g

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

Expand Down
4 changes: 4 additions & 0 deletions src/ApiError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HTTPError, RequestError } from 'got'
export interface TransloaditErrorResponseBody {
error?: string
message?: string
reason?: string
assembly_ssl_url?: string
assembly_id?: string
}
Expand All @@ -16,6 +17,8 @@ export class ApiError extends Error {

rawMessage?: string

reason?: string

assemblySslUrl?: string

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

super(message)
this.rawMessage = body.message
this.reason = body.reason
this.assemblyId = body.assembly_id
this.assemblySslUrl = body.assembly_ssl_url
this.code = body.error
Expand Down
10 changes: 7 additions & 3 deletions test/unit/mock-http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,18 @@ describe('Mocked API tests', () => {
it('should throw error with error code', async () => {
const client = getLocalClient()

nock('http://localhost')
.post(createAssemblyRegex)
.reply(400, { error: 'INVALID_FILE_META_DATA', message: 'Invalid file metadata' })
nock('http://localhost').post(createAssemblyRegex).reply(400, {
error: 'INVALID_FILE_META_DATA',
message: 'Invalid file metadata',
reason: 'Some reason',
})

await expect(client.createAssembly()).rejects.toThrow(
expect.objectContaining<ApiError>({
name: 'ApiError',
code: 'INVALID_FILE_META_DATA',
rawMessage: 'Invalid file metadata',
reason: 'Some reason',
message: 'API error (HTTP 400) INVALID_FILE_META_DATA: Invalid file metadata',
})
)
Expand Down Expand Up @@ -165,6 +168,7 @@ describe('Mocked API tests', () => {
expect.stringMatching(` at .+`),
expect.stringMatching(` code: 'INVALID_FILE_META_DATA',`),
expect.stringMatching(` rawMessage: 'Invalid file metadata',`),
expect.stringMatching(` reason: undefined,`),
expect.stringMatching(
` assemblySslUrl: 'https:\\/\\/api2-oltu\\.transloadit\\.com\\/assemblies\\/foo'`
),
Expand Down