A simple method used throughout Libauth to format error messages. By
formatting errors this way, downstream consumers can detect specific error
types by matching the errorType. For example, the error:
Using this method ensures consistency across the library.
Remarks
In Libauth, expected errors use the type string rather than Error (or
other objects that inherit from Error) to simplify the resulting types and
typechecking requirements. This ensures consistency of returned errors in all
environments, avoids exposing internal details like stack traces and line
numbers, and allows error messages to be recorded or used as text without an
intermediate toString() method.
Parameters
errorType: string
the error enum member representing this error type
Optional errorDetails: string
optional, additional details to include in the error
message
A simple method used throughout Libauth to format error messages. By formatting errors this way, downstream consumers can detect specific error types by matching the
errorType
. For example, the error:Can be detected with
String.includes()
, even if theSomeTypeOfError.exceedsMaximum
error message changes:Using this method ensures consistency across the library.
Remarks
In Libauth, expected errors use the type
string
rather thanError
(or other objects that inherit fromError
) to simplify the resulting types and typechecking requirements. This ensures consistency of returned errors in all environments, avoids exposing internal details like stack traces and line numbers, and allows error messages to be recorded or used as text without an intermediatetoString()
method.