Pat M
Pat M

Reputation: 6036

How to Simulate a 404 Not Found Api endpoint with EmberJs Mirage

In config.js of Mirage. For example:

this.get('path/to/endpoint', (schema, request) => {
  return '404';
});

How should the returned response be formatted so that Mirage treats it like a real 404?

Upvotes: 1

Views: 625

Answers (2)

Gennady Dogaev
Gennady Dogaev

Reputation: 5991

import Response from 'ember-cli-mirage/response';

this.get('path/to/endpoint', (schema, request) => {
  return new Response(404);
});

Found here. For me new Mirage.Response worked too.

Upvotes: 3

Trenton Trama
Trenton Trama

Reputation: 4930

If you want to return a "non-standard" status with mirage, add the response to the end of the verb.

this.get('path/to/endpoint', undefined, 404);
//OR
this.get('path/to/endpoint', {message:'Nothing found'}, 404);

See the route documentation for mirage for a little more information.

Upvotes: 1

Related Questions