scharnyw
scharnyw

Reputation: 2686

RESTful response for data corruption in a single entity when getting multiple entities

I'm currently facing a dilemma in choosing the most appropriate response for a REST API that GET multiple entities, when one of the entities has a data corruption error. Say I have a REST API like the following:

GET /employees?department=&manager=

that returns a list of employees, perhaps with some filtering applied.

When getting the data from upstream (a DB, or another web service, etc.), I discover that the data for one of the employees that match the condition is corrupted. For example, the data cannot be parsed or does not meet some precondition that is necessary for that data entity.

What would be the most appropriate (from an API point of view) RESTful response to this? Should I continue processing all the other employees and simply ignore the error and omit it in the response, or error out with 500 Internal Server Error, or include the error in the response in a separate field while returning the other "good" employees?

I know this is somewhat opinion-based, but some advice would be greatly appreciated.

Upvotes: 1

Views: 463

Answers (1)

Evert
Evert

Reputation: 99717

If you want to return an error, this (to me) is a server-error and I think that 500 is indeed the most appropriate error.

Whether you want to return an error, or an incomplete list with warnings depends on what your application requires it to do.

Upvotes: 1

Related Questions