From aa8f4924b013a67be6bc8a0a6bff6a7f27a6a35c Mon Sep 17 00:00:00 2001 From: Jan Paepke Date: Tue, 29 Nov 2022 14:34:01 +0100 Subject: [PATCH] exposing ApiError as MollieApiError --- src/createMollieClient.ts | 1 + src/data/global.ts | 10 ---------- src/errors/ApiError.ts | 3 ++- tests/unit/errors.test.ts | 6 +++--- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/createMollieClient.ts b/src/createMollieClient.ts index 1a186cf5..5175e19b 100644 --- a/src/createMollieClient.ts +++ b/src/createMollieClient.ts @@ -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'; diff --git a/src/data/global.ts b/src/data/global.ts index 276f689b..48185d12 100644 --- a/src/data/global.ts +++ b/src/data/global.ts @@ -141,13 +141,3 @@ export enum SequenceType { first = 'first', recurring = 'recurring', } - -export type MollieApiErrorLinks = Record & Links; - -export interface MollieApiError { - status?: number; - title: string; - detail: string; - field?: string; - _links?: MollieApiErrorLinks; -} diff --git a/src/errors/ApiError.ts b/src/errors/ApiError.ts index e2db98e1..fcbc9c32 100644 --- a/src/errors/ApiError.ts +++ b/src/errors/ApiError.ts @@ -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 & Links; type MetaInfo = { field?: string; statusCode?: number; diff --git a/tests/unit/errors.test.ts b/tests/unit/errors.test.ts index 2e749738..b097685a 100644 --- a/tests/unit/errors.test.ts +++ b/tests/unit/errors.test.ts @@ -1,4 +1,4 @@ -import { PaymentCreateParams } from '../..'; +import { MollieApiError, PaymentCreateParams } from '../..'; import wireMockClient from '../wireMockClient'; describe('errorHandling', () => { @@ -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'); } @@ -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'); } });