npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redact-axios-error

v4.0.3

Published

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

Downloads

45

Readme

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]"
  }
}