Error Handling Flashcards

(13 cards)

1
Q

Developer Exception Page Middleware

A

Detailed information about unhandled exceptions for both sync and async. By default enabled when in DEV. Never do in PROD. Contains stack trace query parameters of the request cookies headers endpoint meta data. For complete information we need to use logger. It is formatted based on accept header of request- content Negotiation

HTML page returned as plain text instead for example

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Exception Handler Middleware. How to configure with route

A

Configure it if in PROD. Pass a route in it. Make a controller action for that route to return problem() problemdetails. It sends RFC compliant payload to client.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why isn’t my request reaching the error endpoint

A

Don’t make the action with any http verb. Explicit verb will not let some request go to it.

Put [AllowAnonymous] to allow unauthenticated users

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

I don’t want the error route to come in docs

A

Use [ApiExploreSettings(IgnoreApi=true)] to not make open api to doc it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Difference between developer exceptions and exception handler

A

One meant for development to provide full stack trace and additional data for developers to debug the issue. But this data is sensitive and shouldn’t be shown in production of security risk and bad ux. In prod use exception handler to only provide necessary client friendly erro information and hide sentive data like stack trace. Both can follow content Negotiation and catch unhandled exceptions only

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is error result

A

Any result with code 400 and above

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Do we have to configure problem details

A

Error status codes that is above 400 is wrapped in problem details by default

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is problem details

A

Report errors in RFC compliant format. By default it is a json

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is statuscodepages

A

Any 4xx error is converted into problem details as Response

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Does exception handler give out problem details in every unhandled exception

A

No. If the body has not been written, only then.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can we customise problemdetails

A

In services.AddProblemDetails options customise problem details

Use httpcontext features and get the type of feature and edit the context.problemdetails

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to handle validation failure erro response

A

The response type is validation problemdetails when model validation fails which is automatically done

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to give more context to the exceptions of action

A

Create a custom exception classes called httpResponseException inheriting exception with status code and object to hold exception object which is Nullable

Then create a action filter called httpresponseexceptionfilter and leave the action executing but implement action executed. There check if the exception in action context is of type of custom class then create result as objectresult with custom class and give status code. Set the exception handled as true. We can also make it ordered filter with max value to make it run at end of pipeline.

Then register it globally in services.addcontrollers options.filter.add

How well did you know this?
1
Not at all
2
3
4
5
Perfectly