menes-dotnet/Menes

Make exception default messages consistent

idg10 opened this issue · 0 comments

idg10 commented

Some of our exceptions, e.g. OpenApiBadRequestException define a default message in their zero-arguments constructor. Some, e.g. OpenApiUnauthorizedException, do not.

We should be consistent about this. That probably means adding messages in the cases where they are not present.

This came up in a project, and @mwadams had this comment:

We don't typically provide a message for an Unauthorized exception, do we? Why would we?

In most cases we don't really expect this exception to be reported. Its purpose is to provide a way for us to signal to Menes that we need to bail out of processing and fail, without being obliged to unwind the entire call stack manually and return a suitable response code. So typically, application code throws this, and Menes catches it without looking at the message and produces a suitable response.

Since the exception will be handled without ever looking at the message, there is arguably no need for a message. However, there are various debug and diagnostic scenarios in which an exception might be inspected, so as a general rule it's good practice to have a meaningful Message even if in most cases you don't expect it to be used.