# AxiosError: “Request failed with status code 4xx / 5xx”

> AxiosError: Request failed with status code 400, 401, 404 or 500. Read error.response.data, then fix the request, the token, the URL or the server.

Canonical: https://app369.com/fix/axios-request-failed-with-status-code/
Last updated: 2026-11-08

An Axios call rejects with AxiosError: Request failed with status code 401 (or 400, 403, 404, 422, 500). Unlike a network error, the server did answer: Axios treats any status outside 200 to 299 as an error by default. The status code says which side to fix, and the server usually explains why in the response body.

**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**

1. 01 ### **Read the response before guessing**
  > “The request was made and the server responded with a status code” [**Axios, Handling errors**](https://axios-http.com/docs/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;
}
```
2. 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;
});
```
3. 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.
4. 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**](https://axios-http.com/docs/handling_errors) 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 November 8, 2026: [Axios docs: Handling errors](https://axios-http.com/docs/handling_errors).

## **Rather hand it over?**

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

- [from $450**App Fix Ticket**One reproducible bug in an existing mobile or web app, diagnosed and fixed.**See scope and start**](https://app369.com/fixed-price/flutter-firebase-bug-fix/)
- [from $450**AI-Built App Rescue**A 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**](https://app369.com/fixed-price/ai-app-rescue/)

Related: [**Axios “Network Error”**](https://app369.com/fix/axios-network-error/) · [**“TypeError: Failed to fetch”**](https://app369.com/fix/typeerror-failed-to-fetch/) · [**“Unexpected token < in JSON”**](https://app369.com/fix/unexpected-token-in-json/)

Questions

## **More on this error**

<details>

<summary>**What is the difference from Axios “Network Error”? **+</summary>

Request failed with status code means the server answered with an error status. Network Error means no readable answer arrived at all, usually CORS, mixed content or an unreachable host.

</details>

<details>

<summary>**It works in Postman but returns 401 in the app. Why? **+</summary>

Postman sends the token you pasted; the app may not attach it, or sends it before it has loaded. Compare the request headers in the browser’s Network tab with the ones Postman sends.

</details>

<details>

<summary>**Can you fix it for me? **+</summary>

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. 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.

</details>

A different error?

## **Describe it and get a written quote**

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; Simon replies by email, usually within one business day.

[**Describe your problem **→](https://app369.com/contact/) [**All fixes**](https://app369.com/fix/)