Skip to content

Commit 245267f

Browse files
authored
fix: missing statusCode in ErrorRespnse type (#567)
1 parent 56bee44 commit 245267f

File tree

11 files changed

+49
-2
lines changed

11 files changed

+49
-2
lines changed

src/broadcasts/broadcasts.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('Broadcasts', () => {
2424
it('missing `from`', async () => {
2525
const response: ErrorResponse = {
2626
name: 'missing_required_field',
27+
statusCode: 422,
2728
message: 'Missing `from` field.',
2829
};
2930

@@ -42,6 +43,7 @@ describe('Broadcasts', () => {
4243
"error": {
4344
"message": "Missing \`from\` field.",
4445
"name": "missing_required_field",
46+
"statusCode": 422,
4547
},
4648
}
4749
`);
@@ -142,6 +144,7 @@ describe('Broadcasts', () => {
142144
it('throws an error when an ErrorResponse is returned', async () => {
143145
const response: ErrorResponse = {
144146
name: 'invalid_parameter',
147+
statusCode: 422,
145148
message:
146149
'Invalid `from` field. The email address needs to follow the `[email protected]` or `Name <[email protected]>` format',
147150
};
@@ -170,6 +173,7 @@ describe('Broadcasts', () => {
170173
"error": {
171174
"message": "Invalid \`from\` field. The email address needs to follow the \`[email protected]\` or \`Name <[email protected]>\` format",
172175
"name": "invalid_parameter",
176+
"statusCode": 422,
173177
},
174178
}
175179
`);
@@ -195,6 +199,7 @@ describe('Broadcasts', () => {
195199
error: {
196200
message: 'Unable to fetch data. The request could not be resolved.',
197201
name: 'application_error',
202+
statusCode: null,
198203
},
199204
}),
200205
);
@@ -223,6 +228,7 @@ describe('Broadcasts', () => {
223228
message:
224229
'Internal server error. We are unable to process your request right now, please try again later.',
225230
name: 'application_error',
231+
statusCode: 422,
226232
},
227233
}),
228234
);
@@ -384,6 +390,7 @@ describe('Broadcasts', () => {
384390
it('returns error', async () => {
385391
const response: ErrorResponse = {
386392
name: 'not_found',
393+
statusCode: 404,
387394
message: 'Broadcast not found',
388395
};
389396

@@ -407,6 +414,7 @@ describe('Broadcasts', () => {
407414
"error": {
408415
"message": "Broadcast not found",
409416
"name": "not_found",
417+
"statusCode": 404,
410418
},
411419
}
412420
`);

src/contacts/audiences/contact-audiences.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ describe('ContactAudiences', () => {
129129
"error": {
130130
"message": "Missing \`id\` or \`email\` field.",
131131
"name": "missing_required_field",
132+
"statusCode": null,
132133
},
133134
}
134135
`);
@@ -204,6 +205,7 @@ describe('ContactAudiences', () => {
204205
"error": {
205206
"message": "Missing \`id\` or \`email\` field.",
206207
"name": "missing_required_field",
208+
"statusCode": null,
207209
},
208210
}
209211
`);
@@ -283,6 +285,7 @@ describe('ContactAudiences', () => {
283285
"error": {
284286
"message": "Missing \`id\` or \`email\` field.",
285287
"name": "missing_required_field",
288+
"statusCode": null,
286289
},
287290
}
288291
`);

src/contacts/audiences/contact-audiences.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class ContactAudiences {
2727
data: null,
2828
error: {
2929
message: 'Missing `id` or `email` field.',
30+
statusCode: null,
3031
name: 'missing_required_field',
3132
},
3233
};
@@ -51,6 +52,7 @@ export class ContactAudiences {
5152
data: null,
5253
error: {
5354
message: 'Missing `id` or `email` field.',
55+
statusCode: null,
5456
name: 'missing_required_field',
5557
},
5658
};
@@ -70,6 +72,7 @@ export class ContactAudiences {
7072
data: null,
7173
error: {
7274
message: 'Missing `id` or `email` field.',
75+
statusCode: null,
7376
name: 'missing_required_field',
7477
},
7578
};

src/contacts/contacts.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export class Contacts {
102102
data: null,
103103
error: {
104104
message: 'Missing `id` or `email` field.',
105+
statusCode: null,
105106
name: 'missing_required_field',
106107
},
107108
};
@@ -126,6 +127,7 @@ export class Contacts {
126127
data: null,
127128
error: {
128129
message: 'Missing `id` or `email` field.',
130+
statusCode: null,
129131
name: 'missing_required_field',
130132
},
131133
};
@@ -167,6 +169,7 @@ export class Contacts {
167169
data: null,
168170
error: {
169171
message: 'Missing `id` or `email` field.',
172+
statusCode: null,
170173
name: 'missing_required_field',
171174
},
172175
};

src/contacts/topics/contact-topics.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ describe('ContactTopics', () => {
136136
"error": {
137137
"message": "Missing \`id\` or \`email\` field.",
138138
"name": "missing_required_field",
139+
"statusCode": null,
139140
},
140141
}
141142
`);
@@ -298,6 +299,7 @@ describe('ContactTopics', () => {
298299
"error": {
299300
"message": "Missing \`id\` or \`email\` field.",
300301
"name": "missing_required_field",
302+
"statusCode": null,
301303
},
302304
}
303305
`);

src/contacts/topics/contact-topics.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class ContactTopics {
2222
data: null,
2323
error: {
2424
message: 'Missing `id` or `email` field.',
25+
statusCode: null,
2526
name: 'missing_required_field',
2627
},
2728
};
@@ -44,6 +45,7 @@ export class ContactTopics {
4445
data: null,
4546
error: {
4647
message: 'Missing `id` or `email` field.',
48+
statusCode: null,
4749
name: 'missing_required_field',
4850
},
4951
};

src/emails/emails.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe('Emails', () => {
2323
const response: ErrorResponse = {
2424
name: 'missing_required_field',
2525
message: 'Missing `from` field.',
26+
statusCode: 422,
2627
};
2728

2829
fetchMock.mockOnce(JSON.stringify(response), {
@@ -41,6 +42,7 @@ describe('Emails', () => {
4142
"error": {
4243
"message": "Missing \`from\` field.",
4344
"name": "missing_required_field",
45+
"statusCode": 422,
4446
},
4547
}
4648
`);
@@ -318,6 +320,7 @@ describe('Emails', () => {
318320
name: 'invalid_parameter',
319321
message:
320322
'Invalid `from` field. The email address needs to follow the `[email protected]` or `Name <[email protected]>` format',
323+
statusCode: 422,
321324
};
322325

323326
fetchMock.mockOnce(JSON.stringify(response), {
@@ -344,6 +347,7 @@ describe('Emails', () => {
344347
"error": {
345348
"message": "Invalid \`from\` field. The email address needs to follow the \`[email protected]\` or \`Name <[email protected]>\` format",
346349
"name": "invalid_parameter",
350+
"statusCode": 422,
347351
},
348352
}
349353
`);
@@ -369,6 +373,7 @@ describe('Emails', () => {
369373
error: {
370374
message: 'Unable to fetch data. The request could not be resolved.',
371375
name: 'application_error',
376+
statusCode: null,
372377
},
373378
}),
374379
);
@@ -397,6 +402,7 @@ describe('Emails', () => {
397402
message:
398403
'Internal server error. We are unable to process your request right now, please try again later.',
399404
name: 'application_error',
405+
statusCode: 422,
400406
},
401407
}),
402408
);
@@ -552,6 +558,7 @@ describe('Emails', () => {
552558
const response: ErrorResponse = {
553559
name: 'not_found',
554560
message: 'Template not found',
561+
statusCode: 404,
555562
};
556563

557564
fetchMock.mockOnce(JSON.stringify(response), {
@@ -576,6 +583,7 @@ describe('Emails', () => {
576583
"error": {
577584
"message": "Template not found",
578585
"name": "not_found",
586+
"statusCode": 404,
579587
},
580588
}
581589
`);
@@ -589,6 +597,7 @@ describe('Emails', () => {
589597
const response: ErrorResponse = {
590598
name: 'not_found',
591599
message: 'Email not found',
600+
statusCode: 404,
592601
};
593602

594603
fetchMock.mockOnce(JSON.stringify(response), {
@@ -609,6 +618,7 @@ describe('Emails', () => {
609618
"error": {
610619
"message": "Email not found",
611620
"name": "not_found",
621+
"statusCode": 404,
612622
},
613623
}
614624
`);

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
@@ -78,6 +78,7 @@ export class Resend {
7878
data: null,
7979
error: {
8080
name: 'application_error',
81+
statusCode: response.status,
8182
message:
8283
'Internal server error. We are unable to process your request right now, please try again later.',
8384
},
@@ -86,6 +87,7 @@ export class Resend {
8687

8788
const error: ErrorResponse = {
8889
message: response.statusText,
90+
statusCode: response.status,
8991
name: 'application_error',
9092
};
9193

@@ -104,6 +106,7 @@ export class Resend {
104106
data: null,
105107
error: {
106108
name: 'application_error',
109+
statusCode: null,
107110
message: 'Unable to fetch data. The request could not be resolved.',
108111
},
109112
};

src/topics/topics.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ describe('Topics', () => {
5757
const response: ErrorResponse = {
5858
name: 'missing_required_field',
5959
message: 'Missing `name` field.',
60+
statusCode: 422,
6061
};
6162

6263
mockErrorResponse(response, {
@@ -75,6 +76,7 @@ describe('Topics', () => {
7576
"error": {
7677
"message": "Missing \`name\` field.",
7778
"name": "missing_required_field",
79+
"statusCode": 422,
7880
},
7981
}
8082
`);
@@ -88,6 +90,7 @@ describe('Topics', () => {
8890
const response: ErrorResponse = {
8991
name: 'missing_required_field',
9092
message: 'Missing `defaultSubscription` field.',
93+
statusCode: 422,
9194
};
9295

9396
mockErrorResponse(response, {
@@ -106,6 +109,7 @@ describe('Topics', () => {
106109
"error": {
107110
"message": "Missing \`defaultSubscription\` field.",
108111
"name": "missing_required_field",
112+
"statusCode": 422,
109113
},
110114
}
111115
`);
@@ -170,6 +174,7 @@ describe('Topics', () => {
170174
const response: ErrorResponse = {
171175
name: 'not_found',
172176
message: 'Topic not found',
177+
statusCode: 404,
173178
};
174179

175180
mockErrorResponse(response, {
@@ -190,6 +195,7 @@ describe('Topics', () => {
190195
"error": {
191196
"message": "Topic not found",
192197
"name": "not_found",
198+
"statusCode": 404,
193199
},
194200
}
195201
`);
@@ -236,6 +242,7 @@ describe('Topics', () => {
236242
"error": {
237243
"message": "Missing \`id\` field.",
238244
"name": "missing_required_field",
245+
"statusCode": null,
239246
},
240247
}
241248
`);
@@ -284,6 +291,7 @@ describe('Topics', () => {
284291
"error": {
285292
"message": "Missing \`id\` field.",
286293
"name": "missing_required_field",
294+
"statusCode": null,
287295
},
288296
}
289297
`);
@@ -326,6 +334,7 @@ describe('Topics', () => {
326334
"error": {
327335
"message": "Missing \`id\` field.",
328336
"name": "missing_required_field",
337+
"statusCode": null,
329338
},
330339
}
331340
`);

0 commit comments

Comments
 (0)