/** * Fireblocks API * Fireblocks provides a suite of applications to manage digital asset operations and a complete development platform to build your business on the blockchain. - Visit our website for more information: [Fireblocks Website](https://fireblocks.com) - Visit our developer docs: [Fireblocks DevPortal](https://developers.fireblocks.com) * * The version of the OpenAPI document: 1.6.2 * Contact: developers@fireblocks.com * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ import { AxiosRequestConfig, AxiosError } from "axios"; import { FireblocksError, handleError } from "../error/fireblocksError"; describe("Fireblocks Error Tests", () => { describe('HandleError tests', () => { it('Should return full fireblocks error when axios error schema is full', async () => { const axiosError = new AxiosError( "Mocked error message 1", "BAD_REQUEST", {} as AxiosRequestConfig as any, { url: "http://localhost:8080" }, { data: {message: 'Mocked error message 2'}, status: 400, statusText: "BAD_REQUEST", headers: {"X-My-Header": "my-header-value"}, config: {} as AxiosRequestConfig as any, } ); const res = handleError(axiosError); expect(res).toBeInstanceOf(FireblocksError); expect(res).toEqual({ message: "Mocked error message 2", response: { data: {message: 'Mocked error message 2'}, statusCode: 400, headers: {"X-My-Header": "my-header-value"}, }, request: { url: "http://localhost:8080" }, }); }); it('Should return error with message when axios error missing response property', async () => { const axiosError = new AxiosError( "Mocked error message 1", "BAD_REQUEST", {} as AxiosRequestConfig as any, { url: "http://localhost:8080" }, undefined ); const res = handleError(axiosError); expect(res).toBeInstanceOf(FireblocksError); expect(res).toEqual({ message: "Mocked error message 1", response: undefined, request: { url: "http://localhost:8080" }, }); }); it('Should return error with message when axios error missing response and message properties', async () => { const axiosError = new AxiosError( undefined, "BAD_REQUEST", {} as AxiosRequestConfig as any, undefined, undefined ); const res = handleError(axiosError); expect(res).toBeInstanceOf(FireblocksError); expect(res).toEqual({ message: "No response from server", response: undefined, request: undefined, }); }); it('Should not convert error when error is not axios error', async () => { const error = new Error("Mocked error message 1"); const res = handleError(error); expect(res).toBeInstanceOf(Error); expect(res).toEqual(error); }); }); });