Skip to content

Commit

Permalink
fix: Use "422 Unprocessable Entity" when server refuses parcel (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea authored May 14, 2021
1 parent 89c7d6c commit cec782d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/lib/PoWebClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ describe('PoWebClient', () => {
await client.deliverParcel(parcelSerialized, signer);
});

test('HTTP 403 should throw a RefusedParcelError', async () => {
mockAxios.onPost('/parcels').reply(403, null);
test('HTTP 422 should throw a RefusedParcelError', async () => {
mockAxios.onPost('/parcels').reply(422, null);

const error = await getRejection(client.deliverParcel(parcelSerialized, signer));

Expand All @@ -417,7 +417,7 @@ describe('PoWebClient', () => {

test('RefusedParcelError should include rejection reason if available', async () => {
const message = 'Not enough postage';
mockAxios.onPost('/parcels').reply(403, { message });
mockAxios.onPost('/parcels').reply(422, { message });

const error = await getRejection(client.deliverParcel(parcelSerialized, signer));

Expand All @@ -434,7 +434,7 @@ describe('PoWebClient', () => {
expect(error.message).toEqual('Server was unable to get parcel (HTTP 500)');
});

test('HTTP responses other than 20X/403/50X should throw errors', async () => {
test('HTTP responses other than 20X/422/50X should throw errors', async () => {
mockAxios.onPost('/parcels').reply(400, null);

const error = await getRejection(client.deliverParcel(parcelSerialized, signer));
Expand Down
2 changes: 1 addition & 1 deletion src/lib/PoWebClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class PoWebClient implements GSCClient {
}

const errorMessage = response.data?.message;
if (response.status === 403) {
if (response.status === 422) {
throw new RefusedParcelError(
errorMessage ? `Parcel was rejected: ${errorMessage}` : 'Parcel was rejected',
);
Expand Down

0 comments on commit cec782d

Please sign in to comment.