Axios: Error: Request failed with status code 400

Created on 24 Jun 2017  ·  3Comments  ·  Source: axios/axios

I am using axios and trying to post to localhost:3000/posts and getting this error above. Here is the code:

import axios from 'axios';
import {
  GET_ALL_POSTS,
  GET_POST,
  CREATE_POST,
  DELETE_POST,
  UPDATE_POST
} from './types';

const ROOT_URL = 'http://localhost:3000';

export function createPost({content, title}, cb) {
  return function(dispatch) {
    axios.post(`${ROOT_URL}/posts`, {content, title})
      .then((response) => {
        console.log(response);
        dispatch({
          type: CREATE_POST,
          payload: response
        });
      })
      .then(() => cb())
      .catch((error) => {
        if(error.response) {
          console.log(error.response);
        }
        console.log("Problem submitting New Post", error);
      });
  }
}

Most helpful comment

Hey,
Request failed with status code 400 means that request was created, but server returned response with HTTP code 400 (Bad Request).

All 3 comments

Hey,
Request failed with status code 400 means that request was created, but server returned response with HTTP code 400 (Bad Request).

I'm closing this PR as it doesn't seem an issue in Axios but in your web server.

User redux thunk(Middleware) where you can apply asynchronous logics

Was this page helpful?
0 / 5 - 0 ratings

Related issues

richiksc picture richiksc  ·  78Comments

jiimmeh picture jiimmeh  ·  87Comments

youurayy picture youurayy  ·  69Comments

j-planet picture j-planet  ·  70Comments

zackseuberling picture zackseuberling  ·  83Comments