Best way to handle index model error

Hi, I’m trying to use this model with an Int? Id:

    [Route("/customers/{Id}", "GET")]
    public class Customers
    {
        public int? Id { get; set; }
    }

in this service:

var customers = Db.LoadSelect<Customer>(customer => customer.Where(c => c.Id == request.Id));

The problem is how I can handle the 500 error that rises when I pass a non-numeric Id value to the route.
There is a preferred way to do this? I have tried with:

this.ServiceExceptionHandlers.Add((httpReq, request, exception) => {
    return DtoUtils.CreateErrorResponse(request, exception);
});

this.UncaughtExceptionHandlers.Add((req, res, operationName, ex) => {
     res.Write("Error: {0}: {1}".Fmt(ex.GetType().Name, ex.Message));
     res.EndRequest(skipHeaders: true);
});

but it seems doesn’t do anything… I have the same IIS 500 error page.

If it’s an IIS 500 error page it’s likely thrown by ASP.NET IIS before it reaches ServiceStack - this usually happen when sending illegal characters, in which case they can’t be handled in ServiceStack. A RequestBindingException should throw a 404 which you can handle with an UncaughtExceptionHandler.

After debugging a bit I’ve found that the problem was on how I configured the app:

SetConfig(new HostConfig
{
   WriteErrorsToResponse = false
);

WriteErrorsToResponse = false well… doesn’t reports the error :smile: but trigger the IIS 500 error page.