fhstp-mfg / geowahl-api

Provides data API for geo–political data for Web and provides data visualization views.
2 stars 1 forks source link

Add error responses for web services #14

Open miclaus opened 8 years ago

miclaus commented 8 years ago

In case of errors, the web services should respond w/ JSON error object.

Something in the format of http://jsonapi.org/examples/#error-objects would be nice.

Example:

{
  "errors": [
    {
      "status": "422",
      "source": { "pointer": "/data/attributes/first-name" },
      "title":  "Invalid Attribute",
      "detail": "First name must contain at least three characters."
    }
  ]
}

( I guess source is not necesarry in our case, since a simple error message suffices. )

miclaus commented 8 years ago

Not quite what was expected ..

The District Results by id web service now always retrieves an error object, which should not be, since the district is found.

Example: /bpw16b/w/1

{
  errors: {
    status: 420,
    title: "'1' not found",
    detail: "Sorry! We could not find a district with the id '1'."
  }
  district: { ... },
  state: { ... },
  election: { ... }
}

Also if the districtId is set to results like so: /bpw16b/w/results, then instead of retrieving a single error object (since results is not a valid districtId), the following response is retrieved:

{
  errors: {
    status: 420,
    title: "'results' not found",
    detail: "Sorry! We could not find a district with the id 'results'."
  },
  state: { ... }
  election: { ... }
}

It could be argued for, that if there isn't a valid districtId given, at least the state and election results objects should be retrieved besides an error object. However I don't see how an app could integrate this positively.

Was this intended @suits-at, or simply not tested yet?

Furthermore there are some calls, which return Laravel specific error messages and haven't been take into account.

Examples / Todos:

Therefore I reopened the issue.