fairingrey/actix-realworld-example-app

Errors seem to require a special JSON format

fairingrey opened this issue · 1 comments

Errors seem to require a special JSON format, detailed here in the API spec: https://github.com/gothinkster/realworld/tree/master/api#errors-and-status-codes

{
  "errors":{
    "body": [
      "can't be empty"
    ]
  }
}

This is the file where custom errors are generated, so we'll have to make some changes here such that .json(message) takes in a proper object that can be serialized in such a format. More info on that function can be found here, but it takes in a type that impl's Serialize.

FWIW, validation errors does not currently offer any default implementation of Serde's Serialize so we'll have to implement it on our own as described at https://serde.rs/impl-serialize.html or use an existing type that they provide (see my comment below).