Skip to content

My request returns 404

A request to a project’s address gets a 404 in one of two shapes. When the hostname belongs to no project, the body says so:

Project not found

When the project exists but no active mock matched the request, the 404 is a No mock matched problem, sent as application/problem+json, that names the method and path MockHub looked for, without the query string:

{
"type": "https://mockhub.dev/problems/no-mock-matched",
"title": "No mock matched",
"status": 404,
"detail": "No active mock in this project matches GET /nope."
}

It says nothing about why, because it goes to whoever called your address. Try it in the mock editor says why, with an answer like this one:

Request was not matched
Closest mock: Create order
Differences:
- HTTP method does not match (expected: "POST", actual: "GET")

When the request is far from the mock you tried, the answer says only Request was not matched.

The requests your mocks missed appear in Request logs under No mock matched while Log requests no mock answered is on in the project’s settings, as it is for a new project; if it was turned off, turn it back on to record the next ones. Find requests no mock matched walks through it, and through repeating a logged request in Try it.

Start with Why didn’t this match? on the logged request. It replays the request against the closest mocks and says what stopped each one: being inactive, a rule the request failed, a scenario in another state, or a data store record its condition needs. That covers the first three causes below.

The most common cause. Try it on the mock you expected names each rule the request failed, such as URL does not match or HTTP method does not match, with what the mock expects and what the request had.

  1. Open the mock. Check that its Status is Active: an Inactive mock never answers.
  2. Check the method. A mock matches one method, or every method when set to Any method.
  3. Check the path. With Path and query, the query string is compared too, so a mock for /orders does not match /orders?page=2. A Path with parameters matches one non-empty part of the path for each {name}, so /orders/{id} does not match /orders or /orders/, and a typed /orders/:id is a literal path. A Regex path must match the whole path. See Request matching.
  4. Select Save mock and send the request again. A saved change applies from the next request.
Section titled “A query parameter, header, cookie, form or body rule does not hold”

The method and path are right, but another rule is not: a header or cookie the client does not send, a query parameter with another value, a body that does not contain what the rule expects. Try it lists the failed rule.

Some misses are easy to overlook:

  • A JSON path or equals JSON rule never matches a body that is not JSON, and equals JSON misses a body with fields it does not name unless Allow fields and trailing array items the JSON does not name is on.
  • A form field rule reads only a body sent as application/x-www-form-urlencoded. The same fields sent as JSON or multipart count as not sent: equals, matches regex and contains miss, while is absent, does not match regex and does not contain hold.
  • A cookie the client does not send meets only is absent. does not match regex and does not contain miss it.
  • A multipart part rule needs a multipart request with a part that meets it. A rule with a field name needs a multipart/form-data part of that name, written as browsers and curl write it: Content-Disposition: form-data; name="file". A multipart request without a boundary in its Content-Type gets a 400 before any mock is tried.
  1. In Request logs, select Request and response on the request to see exactly what the client sent.
  2. Compare it with the mock’s rules under Which requests it answers. Each value is compared the way the rule says, such as equals or contains, and a regular expression must match the whole value.
  3. Change the rule or the client, and select Save mock.

Why didn’t this match? marks a difference Uncertain when the log did not keep that part as it was sent. A cookie rule is the usual one: projects redact the Cookie header in their logs by default, so the replay cannot send the cookie, and only Try it with the real value can confirm it.

Request matchers lists every rule and comparison.

A mock that belongs to a scenario answers only while the scenario is in the state it requires. Try it starts from the state the project’s scenario is in now, so a 404 there with the request you expect points at the state. Under Start from, choose the state the mock requires and select Preview this response again: if it answers, the scenario is elsewhere.

  1. Open Scenarios in the project and look at the scenario’s current state.
  2. Select Reset to put it back to its start, or send the requests that move it to the state the mock needs.

See Inspect and reset scenario state.

Project not found means no project answers on that hostname: a typing mistake, a project that was deleted or given another subdomain, or a custom domain that is no longer verified. Such requests are not logged anywhere.

  1. Open the project and copy its address from under its name with Copy URL. Use that address, with its scheme, rather than one typed by hand.
  2. If the address is on a custom domain, open Settings → Custom domains and check that the domain shows Verified. If it shows Awaiting DNS, see My domain does not verify.

The path /__admin and every path under it are reserved and always get an empty 404, in any letter case, whatever mocks exist. Move the mock to another path.

The path /__inbox and every path under it are reserved too, the other way round: they answer 200 and never reach a mock. See Receive callbacks in the project inbox.

The project forwards requests to an upstream

Section titled “The project forwards requests to an upstream”

In Proxy unmatched mode a request no mock matches goes to the project’s upstream, and a 404 may be the upstream’s own answer. In Record everything mode every request goes there. Request logs shows Forwarded to your upstream under Answered by for these.

When no Upstream base URL is set, both modes behave like Mock only, and the request gets the 404 No mock matched.

So do they on a plan that does not include forwarding, whatever mode is saved.

  1. To answer the request from MockHub instead, add a mock for it.
  2. Otherwise check the project’s Upstream base URL, and the upstream itself. See Gateway modes.

A mock can return 404 itself: its status code, one step of a response sequence, or an active chaos profile’s injected error. Request logs then names the mock under Answered by. Open it from there and change what it answers.

Report a problem with the time of the request, its method and URL, and the name of the mock you expected to answer.

Report a problem with this page