Handling an error with multiple attributes or parameters using the JSON API

The JSON API indicates that several errors in an attribute / parameter must be specified separately. What is the best way to handle a single error that includes multiple parameters at once?

For example, suppose the endpoint accepts parameters bidor fold, but not both (they are mutually exclusive). What should be the error response if both parameters are represented ( GET /endpoint?bid=100.00&fold=muck)?

List the error twice, once for each attribute?

{
  "errors": [
    {
      "status": "400",
      "source": { "parameter": "bid" },
      "detail": "Cannot accept both 'bid' and 'fold' parameters."
    },
    {
      "status": "400",
      "source": { "parameter": "fold" },
      "detail": "Cannot accept both 'bid' and 'fold' parameters."
    }
  ]
}

Merge Attributes?

{
  "errors": [
    {
      "status": "400",
      "source": { "parameter": ["bid", "fold"] },
      "detail": "Cannot accept both 'bid' and 'fold' parameters."
    }
  ]
}

Make one higher level error for the whole query?

{
  "errors": [
    {
      "status": "400",
      "source": { "pointer": "/data" },
      "detail": "Cannot accept both 'bid' and 'fold' parameters."
    }
  ]
}

Another way?

+4
source share
2 answers

TL DR version: The first is probably correct.

JSONAPI, , /. this:

, , . , , .

, : " , , ?"

, - Cannot accept 'bid' when using 'fold' (, , , ), , , .

, , , , , , , , . , ( ).

JSONAPI :

: , , URI .

string (not Array), , , , , , , , , .

, , , , , .

+3

A - , . , , "" - .

A meta, - .

B , () . , API, , source. :

"source" : [ {parameter...}, {parameter...} ]
+2

Source: https://habr.com/ru/post/1685704/


All Articles