c# - Why is Http code 500 returned although I catch the exception -
although if-clause executed in fiddler see http error 500 , not 404, why that?
public class globalexceptionhandler : exceptionhandler { public override void handle(exceptionhandlercontext context) { if (context.exception resourcenotfoundexception) { context.request.createerrorresponse(httpstatuscode.notfound, context.exception.message); } else { base.handle(context); } } } this in fiddler response:
http/1.1 500 internal server error content-length: 3945 content-type: application/json; charset=utf-8 server: microsoft-iis/7.5 x-powered-by: asp.net date: wed, 08 jul 2015 08:14:45 gmt {"message":"an error has occurred.","exceptionmessage":"the resource not found!","exceptiontype":"erpapplicationendpoints.resourcenotfoundexception","stacktrace":" @ ... removed clarity...
you need set result property on exceptionhandlercontext object in if clause instead of doing createerrorresponse(also incorrect not assigning created httpresponsemessage anything)
context.result = <a-httpactionresult-instance-here>
Comments
Post a Comment