Skip to content

Invalid requests should respond with more detailed info #21

Description

@ritch

@raymondfeng @Schoonology @bajtos

Currently we have poor support for responding with validation errors. Below is an overview of what we have and what I think we should move to. Any suggestions would be helpful before making any changes. This might require changes in the iOS SDK, strong-remoting, and the datasource juggler.

  • Using a simple Todo model (ex 1).
  • Making an HTTP request to create a model (ex 2)
  • Current response (ex 3)
  • Potential / Improved response (ex 4)

ex 1

app.model(
  loopback
    .memory()
    .createModel('todo', {
      task: 'string',
      done: 'boolean',
      owner: {type: 'string', required: true}
    })
)

ex 2

POST /todos HTTP/1.1
Content-Type: application/json

{
  "task": "testing...",
  "done": false
}

ex 3

HTTP/1.1 400 Bad Request

ex 4

HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json

{
  "errors": {
    "owner": ["owner is required"]
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions