How to structure errors in a Typescript & Serverless project

We recommend creating individual files for errors within the utils/errors folder & offering errors as constants or functions that take in variable parameters.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 12/17/2022 at 10:37
Last Updated on 12/17/2022 at 13:48
Two flowers that represent Typescript and Serverless side by side. Beneath it sits the text "Structured Errors".

We recommend creating individual files for errors within the utils/errors folder & offering errors as constants or functions that take in variable parameters.

The following article makes use of our Open Source Serverless & Typescript starter project that is available on Git Hub as well as a series of articles available on our blog.

SubscribeDownload Open Source Starter ProjectHow to create a Typescript & Serverless projectHow to create a structure Typescript & Serverless Function

Place all errors in a single folder

To make sure that you can access errors in a way that is accessible and searched for, we recommend that you place all of the errors in a folder under utils (i.e. utils/errors).

Place errors in subfolders

We recommend breaking down errors into types to further ease finding the right errors. The out of the box Open Source project comes with error for body and common.

Offer errors as constants or variable functions

We breakdown our errors into two types

Constants

These are errors that appear the same regardless of where they are used and tend to be generic. For example - if the whole body is missing.

Variable Functions

These are errors that are offered as functions which make use of a base string to acknowledge an error has occurred and implement a variable to help give the error more details. For example - the function failed as a variable within the body was missing. This function would help you log what variable was missing.

Any Questions ?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.

SubscribeInquireView All PostsView All ServicesView All Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe