This seems to be repeated often, maybe create a helper function that takes an array and the exception and fills it correctly? Same for status code, you probably want to set an HTTP error code