Estoy usando axios e intento publicar en localhost: 3000/posts y obtengo este error arriba. Aquí está el código:
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);
});
}
}
Oye,
Request failed with status code 400
significa que se creó la solicitud, pero el servidor devolvió la respuesta con el código HTTP 400 (Solicitud incorrecta).
Estoy cerrando este PR ya que no parece un problema en Axios sino en su servidor web.
User redux thunk (Middleware) donde puede aplicar lógicas asíncronas
Comentario más útil
Oye,
Request failed with status code 400
significa que se creó la solicitud, pero el servidor devolvió la respuesta con el código HTTP 400 (Solicitud incorrecta).