How should an error be returned to a REST client (if at all)? -
i have rest resource returns tabular data:
http://example.org/api/tables/foo this returns first page of results foo table.
there query parameter add together selection criteria resource:
http://example.org/api/tables/foo?id=bar id=bar not free text query. internally server attempts resolve bar known entity , creates regular look limiting rows returned foo. query succeed bar must id scheme aware of - otherwise regular look cannot generated appropriately.
what's right behavior resource if bar not known system? understand 5xx responses not appropriate since client cannot phone call 1 time again , expect different result. appropriate homecoming 404 response message detailing bar not recognized? or improve homecoming 200 response (since search result) envelope wrapping empty search result detailing bar not found? else entirely?
it depends on business domain.
if phone call unknown entity failure in domain - should provide error status code of 4xx (if understand correctly, resource not found - status code of 404 not found appropriate in here).
if phone call unknown entity ok, yield no results (lets google search yields 0 results) should provide status code of 2xx.
status codes 5xx server error, , tell client there wrong server side. in situation there nil wrong server, status code of 4xx appropriate in here.
by way, don't have utilize error codes every error - if go on business domain, see can utilize little subset of these codes describe errors.
be sure provide detailed message in response person using service much details , info possible.
if can, provide links online resources explaining problem. example, if have developers forum thread discussing exact problem - provide link thread.
if have utilize error codes, utilize string codes rather random numbers, example: utilize "unknown_entity" instead of error number #9842.
example error message:
{ "message" : "unknown entity provided". "description" : "parameter bar not known system.", "errorcode" : "unknown_entity", "links": [ { "rel" : "help", "href" : "http://myforum.com/errors/unkownentityerror", "title" : "my forum" }, ] } rest
No comments:
Post a Comment