SerializationException, Handle multiple inputs?

I have a get coming in with the following parameters /form?type=resource&limit=1000000&select=_id,title&limit=100&skip=0

The problem I’m having is the duplicate limit property which gives the following error:

 {
    "errorCode": "SerializationException",
    "fieldName": "limit",
    "message": "'1000000,100' is an Invalid value for 'limit'"
}

How can I intercept this error and deserailize the second limit value to another property (Take)?

    public class FormRequest : IReturn<FormResponse>, IFormRequest
    {
        public string Type   { get; set; }
        public long   Limit  { get; set; }
        public long   Skip   { get; set; }
        public long   Take   { get; set; }
        public string Select { get; set; }
    }

Since it’s an invalid request ServiceStack will fail to deserialize it and it will be raised as an Uncaught Exception you can handle in an UncaughtExceptionHandlers.

If you prefer you can handle the deserialization of the Request DTO yourself in a Request Converter, otherwise I’d recommend changing your Request DTO to accommodate the requests you want to handle, e.g. using long[] Limit if you want to accept multiple limits or change it to a string and parse it inside your service that way.

1 Like