Skip to content

Commit

Permalink
exposing ApiError as MollieApiError
Browse files Browse the repository at this point in the history
  • Loading branch information
janpaepke committed Nov 29, 2022
1 parent 0050def commit aa8f492
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/createMollieClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,4 @@ export { RefundEmbed, RefundStatus } from './data/refunds/data';
export { SubscriptionStatus } from './data/subscriptions/data';
export { ProfileStatus } from './data/profiles/data';
export { OnboardingStatus } from './data/onboarding/data';
export { default as MollieApiError } from './errors/ApiError';
10 changes: 0 additions & 10 deletions src/data/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,3 @@ export enum SequenceType {
first = 'first',
recurring = 'recurring',
}

export type MollieApiErrorLinks = Record<string, Url> & Links;

export interface MollieApiError {
status?: number;
title: string;
detail: string;
field?: string;
_links?: MollieApiErrorLinks;
}
3 changes: 2 additions & 1 deletion src/errors/ApiError.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { AxiosResponse } from 'axios';

import { idempotencyHeaderName } from '../communication/makeRetrying';
import { MollieApiErrorLinks, Url } from '../data/global';
import { Links, Url } from '../data/global';
import Maybe from '../types/Maybe';

type MollieApiErrorLinks = Record<string, Url> & Links;
type MetaInfo = {
field?: string;
statusCode?: number;
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/errors.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PaymentCreateParams } from '../..';
import { MollieApiError, PaymentCreateParams } from '../..';
import wireMockClient from '../wireMockClient';

describe('errorHandling', () => {
Expand Down Expand Up @@ -34,7 +34,7 @@ describe('errorHandling', () => {
try {
await bluster(client.payments.create.bind(client.payments))(createPaymentParams as PaymentCreateParams);
} catch (error) {
expect(error).toBeInstanceOf(Error);
expect(error).toBeInstanceOf(MollieApiError);
expect(error.field).toBe('amount');
expect(error.message).toBe('The amount is required for payments');
}
Expand All @@ -53,7 +53,7 @@ describe('errorHandling', () => {
try {
await bluster(client.payments.create.bind(client.payments))(createPaymentParams as PaymentCreateParams);
} catch (error) {
expect(error).toBeInstanceOf(Error);
expect(error).toBeInstanceOf(MollieApiError);
expect(error.idempotencyKey).toBe('mock-key');
}
});
Expand Down

0 comments on commit aa8f492

Please sign in to comment.