Saturday, 23 January 2021

Part 8 : Developer Exception Page

#5 minutes of reading

 

In this article I will discuss about developer exception page. Actually, in this and few upcoming articles I will discuss on middleware functionalities. Here I will show you usage of UseDeveloperException middleware.

As name suggest this middleware is for handling exception occurred in application and details exception shown on browser. Browser content for detail exception internally managed by UserDeveloperException middleware and no view gets created in project for showing detail exception on browser window. The details exception is for developer so make sure this middleware configured for developer environment only and not for staging/production environment. Will discuss in detail about environment in coming article.

Create Asp.Net core application project with name ExceptionPage and code available on GitHub.

Open startup.cs file from created project and check below highlighted,

·         app.IsDevelopment() : method return true if environment is developer environment.

·         app.UseDeveloperExceptionPage() : method used for handling error occurred in application.


Till now there is no error in application, if you run application it will show Hello World!. To check details error scenario, need to explicitly raise an error. Throw error in startup.cs file shown in below screen.

Now run application and check the browser window shown below.



It is details exception important while fixing real issue in application.

Make sure UserDeveloperException middleware always on top in order, the order matters.


 

Suppose few of middleware used above UseDeveloperException middleware, and error occurred in middleware which written above UseDeveloperException it won’t give an error. Let’s understand with an example.


Run application and check browser window shown below.

 


It is not showing anything internal server error with status 500.


 

Now lets check one more scenario, modify code based on below screen and add Use middleware in configure method of startup.cs file.


Run application and check browser window.



Instead of error it shows response message from Use middleware. To avoid this comment response message from Use middleware which override previous response with an error from Startup.cs file.


Now run application and check browser window.



 Previous                                                                                                                                                Next

 


0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home