{"id":721,"hash":"632cd9373b95b5608ff94e910b31031e477b8ba0a02adb8bc2726f57609106be","pattern":"How can I get the status code from an HTTP error in Axios?","full_message":"I'm trying to get the error data when a request fails in Axios.\n\naxios\n  .get('foo.example')\n  .then((response) => {})\n  .catch((error) => {\n    console.log(error); //Logs a string: Error: Request failed with status code 404\n  });\n\nInstead of the string, is it possible to get an object with perhaps the status code and content? For example:\n\nObject = {status: 404, reason: 'Not found', body: '404 Not found'}","ecosystem":"npm","package_name":"axios","package_version":null,"solution":"What you see is the string returned by the toString method of the error object. (error is not a string.)\n\nIf a response has been received from the server, the error object will contain the response property:\n\naxios.get('/foo')\n  .catch(function (error) {\n    if (error.response) {\n      console.log(error.response.data);\n      console.log(error.response.status);\n      console.log(error.response.headers);\n    }\n  });","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/39153080/how-can-i-get-the-status-code-from-an-http-error-in-axios","votes":598,"created_at":"2026-04-19T04:51:33.556512+00:00","updated_at":"2026-04-19T04:51:33.556512+00:00"}