axios-error-redact
Version:
Library to redact sensitive information from Axios errors
52 lines (51 loc) • 1.89 kB
TypeScript
import { AxiosError } from 'axios';
import { AxiosErrorRedactorOptions, HttpErrorResponse } from './types';
export * from './types';
export declare const redactedKeyword = "<REDACTED>";
/**
* This class is used to redact sensitive data from Axios error objects.
*/
export declare class AxiosErrorRedactor {
private redactRequestData;
private redactResponseData;
private redactQueryData;
constructor(options?: AxiosErrorRedactorOptions);
/**
* Disables redaction of the request data
* @returns the instance of the redactor
*/
skipRequestData(): AxiosErrorRedactor;
/**
* Disables redaction of the response data
* @returns the instance of the redactor
*/
skipResponseData(): AxiosErrorRedactor;
/**
* Disables redaction of the query data
* @returns the instance of the redactor
*/
skipQueryData(): AxiosErrorRedactor;
/**
* redacts query string from the url
* @param url raw url
* @returns redacted query string
*/
private redactUrlQueryParams;
/**
* Redacts sensitive data from the Axios rejection error
* @param error any of errors that can be thrown by axios
* @returns HttpErrorResponse in case of axios error, otherwise passthrough the error
*/
redactError(error: AxiosError | null | undefined): (HttpErrorResponse | null | undefined | Error);
}
/**
* Simple factory function to create an error interceptor for axios
* @returns error interceptor for axios
*/
export declare function createErrorInterceptor(): ((error: AxiosError | null | undefined) => Promise<HttpErrorResponse | null | undefined | Error>);
/**
* predicate to check if the input is an HttpErrorResponse
* @param input any input
* @returns whether the input is an HttpErrorResponse
*/
export declare function isHttpErrorResponse(input: any): input is HttpErrorResponse;