Is it possible to control what HTTP error code apexrest returns when an exception occurs in the code? By default it returns a 500 error and a developer who's working on the system that's consuming the API is complaining that this is misleading (and I tend to agree). SF defines 500 in this context as an Apex error, but generally 500 is "Internal Server Error" which would suggest more than failed validation.
It seems to throws the 500 on all unhandled exceptions, whether native or custom exceptions. (We're doing a bunch of validation on the input params to the webservices, and throwing custom exceptions when validation fails.)
According to this documentation SF determines the error code automatically.
Is there a better way to handle this? Can I control the error code returned? If so, what's the best pattern here?
Do I try to handle all exceptions and construct a response to return instead?