Short answer
Log error.response.status and error.response.data: the body often names the exact problem. 400 or 422 means the request data is wrong (missing field, wrong format). 401 means no valid credentials: the token is missing, expired or sent in the wrong header. 403 means the user is known but not allowed. 404 means the URL or base URL is wrong, or the record does not exist. 5xx means the server failed: check the server logs at that time, not the client code.
What each status means, and the fix
01
Read the response before guessing
“The request was made and the server responded with a status code” Axios, Handling errors
The error object carries the server’s full answer. Log the status and body together with the URL and method, so every failure tells you its own cause.
try { await api.post('/orders', order); } catch (err) { if (err.response) { console.error(err.config.method, err.config.url, err.response.status, err.response.data); } throw err; }02
401: missing or expired credentials
The token was not attached, was attached under the wrong header, or has expired. Attach it in a request interceptor, and refresh or sign the user in again on 401.
api.interceptors.request.use((config) => { const token = getToken(); if (token) config.headers.Authorization = `Bearer ${token}`; return config; });03
400, 404 and 422: the request itself is wrong
404 usually means a wrong base URL or path (a missing /api prefix, a trailing slash the server treats differently) or an ID that does not exist. 400 and 422 mean the body failed validation: compare what you send with what the endpoint expects, including Content-Type.
04
Statuses you want to handle without throwing
“you can override the default condition (status >= 200 && status < 300) and define HTTP code(s) that should throw an error.” Axios, Handling errors: validateStatus
If a 404 is a normal answer for your app (for example “no profile yet”), let Axios resolve for it and check the status yourself.
const res = await api.get(`/profiles/${id}`, { validateStatus: (s) => (s >= 200 && s < 300) || s === 404, }); if (res.status === 404) return null;
Checked against the vendor’s docs on : Axios docs: Handling errors.
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.See scope and start
Related: Axios “Network Error” · “TypeError: Failed to fetch” · “Unexpected token < in JSON”