# Mirage error responses for jsonAPI ember-data

**URL:** <https://discuss.emberjs.com/t/mirage-error-responses-for-jsonapi-ember-data/16038>\
**Category:** Ember Data\
**Created:** [January 17, 2019, 3:21am UTC](https://discuss.emberjs.com/t/mirage-error-responses-for-jsonapi-ember-data/16038 "2019-01-17T03:21:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![teejay](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/teejay/32/13585_2.png) [@teejay](https://discuss.emberjs.com/u/teejay)\
**Post date:** [January 17, 2019, 3:21am UTC](https://discuss.emberjs.com/t/mirage-error-responses-for-jsonapi-ember-data/16038/1 "2019-01-17T03:21:15Z")

</div>

Hello, I am currently struggling to create a valid error response in mirage for a patch request.

my config looks like this

```
server.patch(`api/v2/students/:id`, function () {
  // example Error response from the server
  return new Mirage.Response(422, {}, {
    errors: [
      {
        'status': 422,
        'title': 'wth',
        'detail': 'login has already been taken',
        'source': {
          'pointer': '/data/attributes/login',
        },
      },
    ],
  })
})

```

and when I try to save the model object via `.save()` I am presented with a super duper annoying error message-\> `The adapter rejected the commit because it was invalid`

I am really a little clueless at this point and I hope someone could help me out with this one. I am using ember 2.18, same for ember data.

---

<div class="post-metadata">

**Author:** ![ryanto](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/ryanto/32/13850_2.png) [@ryanto](https://discuss.emberjs.com/u/ryanto)\
**Post date:** [January 17, 2019, 5:12pm UTC](https://discuss.emberjs.com/t/mirage-error-responses-for-jsonapi-ember-data/16038/2 "2019-01-17T17:12:10Z")

</div>

I think you’re on the right path here. Ember Data is letting you know that the model didn’t successfully save because the mirage server responded with a 422. In fact, if you add `{{model.isInvalid}}` to your template, you’ll see that become true.

I see that your error object has a `detail` of `login has already been taken`. Do you want that displayed on the screen? In the console? Something else?

---

<div class="post-metadata">

**Author:** ![teejay](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/teejay/32/13585_2.png) [@teejay](https://discuss.emberjs.com/u/teejay)\
**Post date:** [January 17, 2019, 8:24pm UTC](https://discuss.emberjs.com/t/mirage-error-responses-for-jsonapi-ember-data/16038/3 "2019-01-17T20:24:03Z")

</div>

Hello, the detail prop has atm the purpose to identify a 422 error and then replace it with a proper translation. In the future our API will return an error code which will be used to do just that. Am I maybe missing headers, like content-type and accept?
