Skip to content

Commit ecbf4ef

Browse files
authored
fix(client): fix DuffelError exporting (#440)
Previously DuffelError was exported as both the types and the object. This led to a naming conflict and caused `DuffelError` to not be importable through `@duffel/api`. To fix that, we will move this class out of `ClientType`, so that it can be imported as both a value and a type.
1 parent b335087 commit ecbf4ef

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

src/Client.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import fetch from 'node-fetch'
22
import { URL, URLSearchParams } from 'url'
3-
import { DuffelError, DuffelResponse, SDKOptions } from './types'
3+
import {
4+
DuffelResponse,
5+
SDKOptions,
6+
ApiResponseMeta,
7+
ApiResponseError,
8+
} from './types'
49

510
export interface Config {
611
token: string
@@ -10,6 +15,23 @@ export interface Config {
1015
source?: string
1116
}
1217

18+
export class DuffelError extends Error {
19+
public meta: ApiResponseMeta
20+
public errors: ApiResponseError[]
21+
22+
constructor({
23+
meta,
24+
errors,
25+
}: {
26+
meta: ApiResponseMeta
27+
errors: ApiResponseError[]
28+
}) {
29+
super()
30+
this.meta = meta
31+
this.errors = errors
32+
}
33+
}
34+
1335
export class Client {
1436
private token: string
1537
private basePath: string

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import {
1010
Payments,
1111
SeatMaps,
1212
} from './booking'
13-
import { Client, Config } from './Client'
13+
import { Client, Config, DuffelError as _DuffelError } from './Client'
1414
import { Aircraft, Airlines, Airports } from './supportingResources'
15-
import { DuffelError as _DuffelError } from './types/ClientType'
1615
export interface DuffelAPIClient {
1716
aircraft: Aircraft
1817
airlines: Airlines

src/types/ClientType.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,6 @@ export interface DuffelResponse<T_Data> {
7575
meta?: PaginationMeta
7676
}
7777

78-
export class DuffelError extends Error {
79-
public meta: ApiResponseMeta
80-
public errors: ApiResponseError[]
81-
82-
constructor({
83-
meta,
84-
errors,
85-
}: {
86-
meta: ApiResponseMeta
87-
errors: ApiResponseError[]
88-
}) {
89-
super()
90-
this.meta = meta
91-
this.errors = errors
92-
}
93-
}
94-
9578
export interface SDKOptions {
9679
/**
9780
* If `true` it will output the path and the method called

0 commit comments

Comments
 (0)