How to handle HTTP 400 Error in Axios

May 29, 2020

Axios is a light weight promised based HTTP client for both nodejs and browser.

Let’s see how to handle 400 error message using it.

What is HTTP 400 status code?

HTTP status code 400 is sent by the server in response to our api call if we have a client side error like the data that we sent is invalid in someway like validation issue

Handling 400 error message in Axios


npm i axios


const axios = require("axios");

const doSomething = async () => {
  try {
    await"", {});
  } catch (error) {

    // Check if it's HTTP 400  error
    if (error.response.status === 400) {
      console.log(`HTTP 400 error occured`);
    // You can get response data (mostly the reason would be in it)
    if ( {
    // TODO: throw error if you want to handle it somewhere
    // throw error;



Here’s a Codesandbox snippet for you to play around

👋 I'm Ashik Nesin • Sr. Frontend Engineer @Chargebee 👨‍💻• I write about modern Javascript & building web apps

© 2021 Nesin Technologies LLP