New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

redact-axios-error

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redact-axios-error

grooms and redacts axios errors to trim them down and make them more useful for logging

  • 4.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29
decreased by-12.12%
Maintainers
1
Weekly downloads
 
Created
Source

redact-axios-error

Axios errors are verbose when stringified and leak URL and header authorization.

This library trims them down to essential information removing circular references. It redacts URL and header authorization. It can optionally be configured to redact any of request, response, and query string data.

Traverses all error properties inspecting for nested AxiosErrors and grooms/redacts to a max depth of at least 5. Traversing is for redacting when an Error has for example a source or a cause AxiosError, however the property name could be anything. The AxiosError should be the final source/cause Error as only select AxiosError properties are copied onto the groomedAxiosError. All AxiosError parent Errors and properties are retained unaltered.

axios-error-redact-interceptor

Can be registerd on axios to redact all response errors before they are thrown.

Requirements

ECMAScript modules (esm), not native esm/.mjs, requires esm

Node 14+

Getting started

npm i -S redact-axios-error

Interceptor Usage

import { getAxiosErrorInterceptor } from 'redact-axios-error/axios-error-redact-interceptor'

axiosClient.interceptors.response.use(null, getAxiosErrorInterceptor())

Optionally, an AxiosErrorGroomer with various configurations can be passed to getAxiosErrorInterceptor.

Usage

const groomer = new AxiosErrorGroomer()
log.error(groomer.getGroomedAxiosError(err), 'Some error message')

OR

log.error(new AxiosErrorGroomer().getGroomedAxiosError(err), 'Some error message')

OR

To redact request, response, and query string data:
log.error(new AxiosErrorGroomer(false, false, false).getGroomedAxiosError(err), 'Some error message')

Methods

  • AxiosErrorGroomer (includeRequestData = true, includeResponseData = true, includeQueryData = true) - constructor, defaults to NOT redact request, response, and query string data
  • getGroomedAxiosError(error) - trims and redacts if AxiosError, otherwise returns the Error unaltered
  • isAxiosError(error) - true if the Error is an Axios error, called by the getGroomedAxiosError method
  • includeRequestData(bool) - default true, false redacts request data
  • includeResponseData(bool) - default true, false redacts response data
  • includeQueryData(bool) - default true, false redacts query string data

Output Error JSON

Bad Server

Not redacting request data or query string

{
  "config": {
    "transformRequest": {},
    "transformResponse": {},
    "timeout": 5000,
    "xsrfCookieName": "XSRF-TOKEN",
    "xsrfHeaderName": "X-XSRF-TOKEN",
    "maxContentLength": -1,
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Content-Type": "application/json",
      "User-Agent": "axios/0.18.0",
      "Content-Length": 13
    },
    "method": "get",
    "baseURL": "http://badServer:3000",
    "data": "{\"some\":true}",
    "url": "http://badServer:3000/?foo=bar"
  },
  "errno": "ENOTFOUND",
  "code": "ENOTFOUND",
  "syscall": "getaddrinfo",
  "port": "3000",
  "request": {}
}

Server Error

Redacting request/response data and query string

{
  "config": {
    "transformRequest": {},
    "transformResponse": {},
    "timeout": 5000,
    "xsrfCookieName": "XSRF-TOKEN",
    "xsrfHeaderName": "X-XSRF-TOKEN",
    "maxContentLength": -1,
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Content-Type": "application/json",
      "Authorization": "[REDACTED]",
      "User-Agent": "axios/0.18.0",
      "Content-Length": 13
    },
    "method": "post",
    "baseURL": "http://localhost:3000",
    "url": "http://localhost:3000/errorPost?[REDACTED]",
    "data": "[REDACTED]"
  },
  "request": {},
  "response": {
    "status": 500,
    "statusText": "Internal Server Error",
    "headers": {
      "x-powered-by": "Express",
      "content-security-policy": "default-src 'self'",
      "x-content-type-options": "nosniff",
      "content-type": "text/html; charset=utf-8",
      "content-length": "3419",
      "date": "Mon, 18 Feb 2019 17:57:52 GMT",
      "connection": "close"
    },
    "data": "[REDACTED]"
  }
}

Keywords

FAQs

Package last updated on 08 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc