Coding⏱️ 2 min read📅 2026-05-31

How to Fix: How can I get the status code from an HTTP error in Axios?

Get error data from Axios HTTP errors in JSON format.

Quick Answer: Use the `response.config` property to access the original request options, which includes the status code. You can then parse the response text to extract additional information.

To get the status code from an HTTP error in Axios, you can use the `config` property of the error object. The `config` property contains the original options passed to the request, which includes the URL and any headers.

💡 How to Get Status Code

  • Use the `config` property of the error object:

Example:

axios.get('foo.example', { headers: { 'Content-Type': 'application/json' } }).then((response) => {}).catch((error) => { console.log(error.config); });

This will log an object with the status code, reason phrase, and response data.

🚀 How to Get Status Code

  • Use the `response.config` property:

Example:

axios.get('foo.example', { headers: { 'Content-Type': 'application/json' } }).then((response) => {}).catch((error) => { console.log(response.config); });

This will log an object with the status code, reason phrase, and response data.

🎯 Final Words

By using the `config` or `response.config` property, you can easily access the status code from an HTTP error in Axios.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions