Custom payload - nomtek/JsonErrors GitHub Wiki

Let's say the code and message is not enough and you need to send some additional information with an error response. For example, the client application needs few more things:

{
  command_status: :incomplete,
  next_try_at: '2021-08-03 13:45:00'
}

Any additional data you can send with every error registered in custom_codes except the code that is marked as validation_errors.

Use JsonErrors::Error facade and add payload as a parameter:

payload = {
  command_status: :incomplete,
  next_try_at: '2021-08-03 13:45:00'
}
JsonErrors::Error.general_error('The command is incomplete', payload)

The response will look like this:

{
  "code":1001,
  "message":"The command is incomplete",
  "payload":{
    "command_status":"incomplete",
    "next_try_at":"2021-08-03 13:45:00"
  }
}