fireblocks / fireblocks-sdk-js

Typescript & Javascript SDK for developers using Fireblocks API
https://docs.fireblocks.com/api/swagger-ui/
MIT License
72 stars 69 forks source link

[Bug] Importing FireBlocks SDK adds a global Axios interceptor via @notabene/pii-sdk #307

Open florian-besser opened 2 weeks ago

florian-besser commented 2 weeks ago

Describe the bug If you import the FireBlocks SDK it in turn imports:

import PIIsdk from "@notabene/pii-sdk";

(See pii-client.d.ts)

This in turn runs the following code:

const $cc4675d9e8e3b77e$var$errorInterceptor = (error)=>{
    return Promise.reject({
        req: {
            url: "" + error?.response?.config?.baseURL + error?.response?.config?.url,
            method: error?.request?.method
        },
        status: error?.response?.status,
        statusText: error?.response?.statusText,
        err: JSON.stringify(error?.response?.data?.err || error?.response?.data || error)
    });
};
(0, ($parcel$interopDefault($iyY9t$axios))).interceptors.request.use((res)=>res, (error)=>$cc4675d9e8e3b77e$var$errorInterceptor(error));
(0, ($parcel$interopDefault($iyY9t$axios))).interceptors.response.use((res)=>res, (error)=>$cc4675d9e8e3b77e$var$errorInterceptor(error));

This sets a default Axios interceptor, from now on any Axios errors will use errorInterceptor which transforms the usual Axios error that has fields like error.request.method into this new (custom?) format that has fields like error.req.method

This is confusing and unexpected; I would expect FireBlocks to decorate their own Axios instance as they desire, but leave all other Axios instances alone.

To Reproduce

import { FireblocksSDK } from 'fireblocks-sdk';
import * as axios from 'axios';

new FireblocksSDK("Some secret", "API key");

// Expect: 0
// Actual: 1
console.log(axios.default.interceptors.response.handlers.length);

Expected behavior No default interceptors should be registered; these interceptors should only be registered on the FireBlocks-SDK-internal axios instance

Version:

florian-besser commented 2 weeks ago

Consider moving to something other than @notabene/pii-sdk or fixing @notabene/pii-sdk to allow adding interceptors only to certain specific Axios instances