Skip to content

Commit 980e996

Browse files
committed
fix: missing statusCode in ErrorRespnse type (#567)
1 parent 4e12b68 commit 980e996

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

src/broadcasts/broadcasts.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('Broadcasts', () => {
1919
it('missing `from`', async () => {
2020
const response: ErrorResponse = {
2121
name: 'missing_required_field',
22+
statusCode: 422,
2223
message: 'Missing `from` field.',
2324
};
2425

@@ -37,6 +38,7 @@ describe('Broadcasts', () => {
3738
"error": {
3839
"message": "Missing \`from\` field.",
3940
"name": "missing_required_field",
41+
"statusCode": 422,
4042
},
4143
}
4244
`);
@@ -137,6 +139,7 @@ describe('Broadcasts', () => {
137139
it('throws an error when an ErrorResponse is returned', async () => {
138140
const response: ErrorResponse = {
139141
name: 'invalid_parameter',
142+
statusCode: 422,
140143
message:
141144
'Invalid `from` field. The email address needs to follow the `email@example.com` or `Name <email@example.com>` format',
142145
};
@@ -165,6 +168,7 @@ describe('Broadcasts', () => {
165168
"error": {
166169
"message": "Invalid \`from\` field. The email address needs to follow the \`email@example.com\` or \`Name <email@example.com>\` format",
167170
"name": "invalid_parameter",
171+
"statusCode": 422,
168172
},
169173
}
170174
`);
@@ -190,6 +194,7 @@ describe('Broadcasts', () => {
190194
error: {
191195
message: 'Unable to fetch data. The request could not be resolved.',
192196
name: 'application_error',
197+
statusCode: null,
193198
},
194199
}),
195200
);
@@ -218,6 +223,7 @@ describe('Broadcasts', () => {
218223
message:
219224
'Internal server error. We are unable to process your request right now, please try again later.',
220225
name: 'application_error',
226+
statusCode: 422,
221227
},
222228
}),
223229
);
@@ -379,6 +385,7 @@ describe('Broadcasts', () => {
379385
it('returns error', async () => {
380386
const response: ErrorResponse = {
381387
name: 'not_found',
388+
statusCode: 404,
382389
message: 'Broadcast not found',
383390
};
384391

@@ -402,6 +409,7 @@ describe('Broadcasts', () => {
402409
"error": {
403410
"message": "Broadcast not found",
404411
"name": "not_found",
412+
"statusCode": 404,
405413
},
406414
}
407415
`);

src/contacts/contacts.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export class Contacts {
6464
data: null,
6565
error: {
6666
message: 'Missing `id` or `email` field.',
67+
statusCode: null,
6768
name: 'missing_required_field',
6869
},
6970
};
@@ -81,6 +82,7 @@ export class Contacts {
8182
data: null,
8283
error: {
8384
message: 'Missing `id` or `email` field.',
85+
statusCode: null,
8486
name: 'missing_required_field',
8587
},
8688
};
@@ -103,6 +105,7 @@ export class Contacts {
103105
data: null,
104106
error: {
105107
message: 'Missing `id` or `email` field.',
108+
statusCode: null,
106109
name: 'missing_required_field',
107110
},
108111
};

src/emails/emails.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('Emails', () => {
1818
const response: ErrorResponse = {
1919
name: 'missing_required_field',
2020
message: 'Missing `from` field.',
21+
statusCode: 422,
2122
};
2223

2324
fetchMock.mockOnce(JSON.stringify(response), {
@@ -36,6 +37,7 @@ describe('Emails', () => {
3637
"error": {
3738
"message": "Missing \`from\` field.",
3839
"name": "missing_required_field",
40+
"statusCode": 422,
3941
},
4042
}
4143
`);
@@ -302,6 +304,7 @@ describe('Emails', () => {
302304
name: 'invalid_parameter',
303305
message:
304306
'Invalid `from` field. The email address needs to follow the `email@example.com` or `Name <email@example.com>` format',
307+
statusCode: 422,
305308
};
306309

307310
fetchMock.mockOnce(JSON.stringify(response), {
@@ -328,6 +331,7 @@ describe('Emails', () => {
328331
"error": {
329332
"message": "Invalid \`from\` field. The email address needs to follow the \`email@example.com\` or \`Name <email@example.com>\` format",
330333
"name": "invalid_parameter",
334+
"statusCode": 422,
331335
},
332336
}
333337
`);
@@ -353,6 +357,7 @@ describe('Emails', () => {
353357
error: {
354358
message: 'Unable to fetch data. The request could not be resolved.',
355359
name: 'application_error',
360+
statusCode: null,
356361
},
357362
}),
358363
);
@@ -381,6 +386,7 @@ describe('Emails', () => {
381386
message:
382387
'Internal server error. We are unable to process your request right now, please try again later.',
383388
name: 'application_error',
389+
statusCode: 422,
384390
},
385391
}),
386392
);
@@ -393,6 +399,7 @@ describe('Emails', () => {
393399
const response: ErrorResponse = {
394400
name: 'not_found',
395401
message: 'Email not found',
402+
statusCode: 404,
396403
};
397404

398405
fetchMock.mockOnce(JSON.stringify(response), {
@@ -413,6 +420,7 @@ describe('Emails', () => {
413420
"error": {
414421
"message": "Email not found",
415422
"name": "not_found",
423+
"statusCode": 404,
416424
},
417425
}
418426
`);

src/interfaces.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ export const RESEND_ERROR_CODES_BY_KEY = {
2020

2121
export type RESEND_ERROR_CODE_KEY = keyof typeof RESEND_ERROR_CODES_BY_KEY;
2222

23-
export interface ErrorResponse {
23+
export type ErrorResponse = {
2424
message: string;
25+
statusCode: number | null;
2526
name: RESEND_ERROR_CODE_KEY;
26-
}
27+
};
2728

2829
export type Tag = { name: string; value: string };

src/resend.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class Resend {
7272
data: null,
7373
error: {
7474
name: 'application_error',
75+
statusCode: response.status,
7576
message:
7677
'Internal server error. We are unable to process your request right now, please try again later.',
7778
},
@@ -80,6 +81,7 @@ export class Resend {
8081

8182
const error: ErrorResponse = {
8283
message: response.statusText,
84+
statusCode: response.status,
8385
name: 'application_error',
8486
};
8587

@@ -98,6 +100,7 @@ export class Resend {
98100
data: null,
99101
error: {
100102
name: 'application_error',
103+
statusCode: null,
101104
message: 'Unable to fetch data. The request could not be resolved.',
102105
},
103106
};

0 commit comments

Comments
 (0)