add argument for customizable error response

I am using this for a JSON REST API, so I wanted the option to be able to return custom error responses, thought others might find it useful :)