Accepted answer

Axios is probably parsing the response. I access the error like this in my code:

  method: 'post',
  responseType: 'json',
  url: `${SERVER_URL}/token`,
  data: {
 .then(response => {
 .catch(error => {
   dispatch({ type: AUTH_FAILED });
   dispatch({ type: ERROR, payload: });

From the docs:

The response for a request contains the following information.

  // `data` is the response that was provided by the server
  data: {},

  // `status` is the HTTP status code from the server response
  status: 200,

  // `statusText` is the HTTP status message from the server response
  statusText: 'OK',

  // `headers` the headers that the server responded with
  headers: {},

  // `config` is the config that was provided to `axios` for the request
  config: {}

So the catch(error => ) is actually just catch(response => )


I still dont understand why logging the error returns that stack message. I tried logging it like this. And then you can actually see that it is an object.

console.log('errorType', typeof error);
console.log('error', Object.assign({}, error));


After some more looking around this is what you are trying to print. Which is a Javascipt error object. Axios then enhances this error with the config, code and reponse like this.

console.log('error', error);
console.log('errorType', typeof error);
console.log('error', Object.assign({}, error));
console.log('getOwnPropertyNames', Object.getOwnPropertyNames(error));
console.log('stackProperty', Object.getOwnPropertyDescriptor(error, 'stack'));
console.log('messageProperty', Object.getOwnPropertyDescriptor(error, 'message'));
console.log('stackEnumerable', error.propertyIsEnumerable('stack'));
console.log('messageEnumerable', error.propertyIsEnumerable('message'));


I recommend handling errors via Axios interceptors, individually for each case scenario:

// interceptor to catch errors
const errorInterceptor = (error) => {
  // check if it's a server error
  if (!error.response) {
    console.log('📡 API | Network/Server error')
    return Promise.reject(error)

  // all the error responses
  switch (error.response.status) {
    case 400:
      console.error(error.response.status, error.message)
      console.log('📡 API | Nothing to display', 'Data Not Found')

    case 401: // authentication error, logout the user
      console.log('📡 API | Please login again', 'Session Expired')

    case 403:
      console.error(error.response.status, error.message)
      console.log('📡 API | Access denied', 'Data Not Found')

    case 404:
      console.error(error.response.status, error.message)
      console.log('📡 API | Dataset not found', 'Data Not Found')

    case 422:
      console.error(error.response.status, error.message,
      console.log('📡 API | Validation error', 'Unprocessable Content')

      console.error(error.response.status, error.message)
  return Promise.reject(error)


You can use inline if else statement like so:

.catch(error => {
        type: authActions.AUTH_PROCESS_ERROR,
        error: error.response ? : 'Something went wrong, please try again.'


The only thing what helped me was the following:

axios.put('/api/settings', settings, {
  validateStatus: status => status >= 200 && status < 300 || status === 422


I was also stumped on this for a while. I won't rehash things too much, but I thought it would be helpful to others to add my 2 cents.

The error in the code above is of type Error. What happens is the toString method is called on the error object because you are trying to print something to the console. This is implicit, a result of writing to the console. If you look at the code of toString on the error object.

Error.prototype.toString = function() {
  'use strict';

  var obj = Object(this);
  if (obj !== this) {
    throw new TypeError();

  var name =;
  name = (name === undefined) ? 'Error' : String(name);

  var msg = this.message;
  msg = (msg === undefined) ? '' : String(msg);

  if (name === '') {
    return msg;
  if (msg === '') {
    return name;

  return name + ': ' + msg;

So you can see above it uses the internals to build up the string to output to the console.

There are great docs on this on mozilla.

score:8'http://localhost:8000/api/auth/register', {
    username : 'test'
}).then(result => {
}).catch(err => {

add in catch geting error response ==>


Here is the proper way to handle the error object:

axios.put(this.apiBaseEndpoint + '/' + id, input)
.then((response) => {
    // Success
.catch((error) => {
    // Error
    if (error.response) {
        // The request was made and the server responded with a status code
        // that falls out of the range of 2xx
        // console.log(;
        // console.log(error.response.status);
        // console.log(error.response.headers);
    } else if (error.request) {
        // The request was made but no response was received
        // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
        // http.ClientRequest in node.js
    } else {
        // Something happened in setting up the request that triggered an Error
        console.log('Error', error.message);

Origin url



getUserList() {
    return axios.get('/users')
      .then(response =>
      .catch(error => {
        if (error.response) {

Check the error object for response, it will include the object you're looking for so you can do error.response.status

enter image description here

Related Query

More Query from same tag