Skip to content
Latchkey

Dredd "fail: statusCode: expected 200" in CI

Dredd sends the requests described in your API Blueprint or OpenAPI document and compares each live response to the documented one. A "statusCode: expected 200 but got 500" failure means the running API diverged from its description.

What this error means

Dredd reports "fail: GET /users duration ..." with "statusCode: expected 200 but got 500" (or a body mismatch), and exits non-zero.

dredd
fail: GET (200) /users duration: 42ms
body: Real and expected data does not match.
statusCode: Expected status code '200', but got '500'.

Common causes

The live API diverged from its description

The implementation returns a different status or body than the API description declares, so Dredd flags the mismatch.

Missing setup makes the endpoint error

A resource the documented example references does not exist (no seeded record, no auth), so the endpoint returns 500 or 404 instead of the documented 200.

How to fix it

Seed state and auth with Dredd hooks

  1. Write hooks that create prerequisite records and add auth headers before each transaction.
  2. Point Dredd at the hooks file so the endpoint returns the documented response.
  3. Re-run so status and body match the description.
Terminal
dredd apiary.apib http://localhost:3000 \
  --hookfiles=./dredd-hooks.js

Update the description or the implementation

If the mismatch is a real drift, fix whichever side is wrong so the documented and live responses agree.

dredd-hooks.js
// dredd-hooks.js
const hooks = require('hooks');
hooks.beforeEach((tx) => {
  tx.request.headers['Authorization'] = 'Bearer ' + process.env.API_TOKEN;
});

How to prevent it

  • Keep the API description and implementation in lockstep.
  • Use hooks to seed state and inject auth for documented examples.
  • Run Dredd in CI so drift is caught in review.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →