Registry / testing / axios-normalizer

axios-normalizer

JSON →
library1.0.2jsnpmunverified

Utility library for normalizing axios HTTP responses and errors, version 1.0.2. It standardizes the response structure to match API documentation, abstracting away axios's wrapping of data in a `data` property and handling errors as exceptions. Suitable for projects using axios ^0.27.2. Differentiators: guarantees consistent response shape, distinguishes API errors from network errors, and normalizes errors only from the API server. Release cadence: infrequent (latest 2022). Peer dependency on axios.

npm install axios-normalizer
INSTALL
IMPORT
SIG · AXIOS-NORMALIZER
A
axios-normalizer
testingjavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

normalizeResponse
import { normalizeResponse } from 'axios-normalizer';
const { normalizeResponse } = require('axios-normalizer');
The package may be ESM/CJS mixed; but to be safe use ESM import for async loading.
normalizeError
import { normalizeError } from 'axios-normalizer';
const normalizeError = require('axios-normalizer').normalizeError;
Named export, not default. Avoid destructuring from CommonJS require because it may be undefined if the package uses ESM.

Demonstrates using normalizeResponse and normalizeError with an axios instance to handle API responses and errors consistently.

import axios from 'axios'; import { normalizeResponse, normalizeError } from 'axios-normalizer'; const axiosInstance = axios.create({ baseURL: 'https://api.example.com' }); axiosInstance.post('/endpoint', { key: 'value' }) .then(normalizeResponse) .catch(normalizeError) .then(result => { // result is normalized: matches API response shape console.log(result); }) .catch(err => { // network errors still throw console.error(err); });
Debug
Known issues
gotchanormalizeError only handles API errors (e.g., 4xx/5xx with JSON body); network errors are rethrown and must be caught separately.
fix
Always chain a second .catch for network errors or use try/catch with async/await.
affects: >=1.0.0
gotchaPackage only supports axios ^0.27.2; may break with newer major versions (0.28.x or 1.x).
fix
Pin axios to exactly 0.27.2 or test compatibility before upgrading.
affects: >=1.0.0
deprecatedNo updates since 2022. Potential abandonment; no TypeScript definitions provided.
fix
Consider writing custom normalization or using a maintained alternative.
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught TypeError: normalizeResponse is not a function
Incorrect import: using default import instead of named import or not importing at all.
fix
Use named imports: import { normalizeResponse } from 'axios-normalizer';
Cannot find module 'axios-normalizer'
Package not installed or missing from package.json.
fix
Run: npm install axios-normalizer --save
TypeError: Cannot read properties of undefined (reading 'data')
Using normalizeResponse on a non-axios response object or calling it outside a .then chain.
fix
Ensure normalizeResponse is called with the axios response object: .then(normalizeResponse)
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
axiosrequiredPeer dependency: works only with axios versions ^0.27.2
Agent activity
19 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
axios-normalizer — npm install axios-normalizer · libregistry