Skip to main content
REST API

400 Bad Request

ErrorValidateRequestEasy

What you will learn

  • Distinguish 400 Bad Request (syntax) from 422 Unprocessable Entity (semantics)
  • Validate error envelope shape (code, message, hint) — clients rely on it for UX
  • Assert field-level validation details are present for every invalid input

Description

Handle malformed request body or invalid parameters.

Test Scenario

const response = await request.post('/api/v1/users', {
  data: { email: 'not-an-email' } // Invalid email format
});
expect(response.status()).toBe(400);
Endpoint/api/v1/errors/400

Testing Tips

  • •Send invalid JSON
  • •Check error message in response
  • •Verify error format consistency
// Playwright - 400 Bad Request
import { test, expect } from '@playwright/test';
test('400 Bad Request for invalid data', async ({ request }) => {
const response = await request.post('/api/v1/users', {
data: { invalid: 'data' } // Missing required fields
});
expect(response.status()).toBe(400);
// Errors use the envelope: { success: false, error: { code, message } }
const body = await response.json();
expect(body.success).toBe(false);
expect(body.error.code).toBe('VALIDATION_ERROR');
});

Challenge ID: rest-error-400

2 frameworks available

API Playground

Send requests and inspect responses

Endpoint: /api/v1/errors/400

Press Enter to send