I explore using a system of layered error types to provide a more precise reason for why something went wrong to the user or stakeholders.
Error
and Exception
interchangeably ) class that JavaScript provides was not going to be enough. I decided to come up with a Layered Error Handling approach. To better visualise this, I made this super technical drawing:
instanceof
check here to see where the error originated from. Now, the subjects I provide are a bit more specific than that and can be whatever you want. The default
is useful to provide an error if something completely unexpected happened. It might seem bad at first, but this will allow you to run through locally with the input data and narrow down where something went wrong. Allowing you to strengthen your code and tests, and assign an appropriate exception type to this problem.
instanceof
check in the example getSubject
method above.
constructor
to take in specific data based on the exception and construct a message that will go into the body of the service ticket.
error.message
prop to populate the body of the Service Ticket. However, for some exceptions, I do need to provide a bit more information to help the client and debugging. For this, I created an ITicketException
interface that an Error
can implement to construct a more complicated error message.
---
would be details that the client may be able to use to solve the issue (if possible from their end), otherwise, I am able to check the other details and quickly use the payload to debug the issue locally. If I am not able to narrow down the details, I can track down the logs in Azure to further help with the debugging effort.
Similarly to the getSubject
method, I also have a getContent
method.
ITicketException
is not a class
we can’t use the instanceof
check, I created a helper to determine if a particular error implements the interface.