Web api error code with message. RRS feed

  • Question

  • Good morning 

             I am Moin and new in development field ,I am creating web api simple project and handling exception globally, in api controller I am throwing exception manually and overriding OnException method and using Application_Error method .Some exception OnException method catching for that exception want to get code dynamically to return mvc application but not able to get error code how to get error code dynamically with message in OnException method. And another problem is Application_Error method not firing how to solve this.Please help me .

    Thanks in Last.

    Monday, September 2, 2019 2:03 AM

All replies

  • Hi,

    Create a Web API exception filter to abstract out your error handling logic from Application_Error into its own function. 

    Errors from Web API do not trigger the Application_Error event. But we can create an exception filter and register it to handle the errors. See Global Error Handling in ASP.NET Web API 2.

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 2, 2019 6:56 AM