4xx Client errors

HTTP 400 Bad Request

HTTP 400 Bad Request means the server could not process the request because the client sent something malformed or invalid.

What 400 Bad Request means

A 400 is the general "your input is wrong" answer: invalid JSON, a missing required field, a value of the wrong type. The response body should say which field is wrong so the client can fix it.

Common causes

  • Malformed JSON in the body (express.json() rejects it).
  • A required field is missing or has the wrong type.
  • An invalid query parameter, such as page=abc.

How to fix or use it

Validate every input at the edge, for example with Zod, and return 400 with field-level messages. Some APIs use 422 for well-formed but semantically invalid data; pick one convention and keep it.

Express (Node.js) example

const schema = z.object({ email: z.string().email() });
app.post('/api/subscribe', (req, res) => {
  const parsed = schema.safeParse(req.body);
  if (!parsed.success) return res.status(400).json({ errors: parsed.error.flatten().fieldErrors });
  // ...
});

SEO impact

Pages that answer 400 are not indexed. If public URLs return 400 because of tracking parameters, accept and ignore unknown parameters instead.

Other 4xx Client errors codes