Throw custom exceptions instead of ArgumentException
atlefren opened this issue · comments
I'm using NetTopologySuite.IO.GeoJSON4STJ in an ASP.net Core API, in order to let users POST data on the form
public class GeometryRequest
{
public Geometry Geometry { get; set; }
}
This works great, and lets me handle Geometries as any other types, and users can post
{
"geometry": {"type":"Point","coordinates":[1, 2]}
}
All good
Untill someone Posts
{
"geometry": {"type":"Pooint","coordinates":[1, 2]}
}
Then aspnet returns a 500 error message, with the message "Requested value 'Pooint' was not found."
I've treied digging into this and found that an ArgumentException is indeed thrown, but in my Error controller I have no way of knowing that this happened in the StjGeometryConverter created by
options.JsonSerializerOptions.Converters.Add(new GeoJsonConverterFactory());
My thinking is that if StjGeometryConverter had thrown a custom exception, I would be able to handle these.
Or, maybe I'm not just familiar enough with ASP.net Core?
I still think "500 internal server error" is the wrong status code for "your geojson is invalid", 400 bad request is better. I know this isn't decided by you (by defaul exceptions are translated to 500), but some way of identifying these exceptions would be great
NetTopologySuite.IO.ParseException
would be a good choice, but maybe the ArgumentException
is not thrown by our code.