How to structure errors in a Typescript & Serverless project

Oscar de la Hera Gomez
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.

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


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 with any thoughts or feedback you may have.

delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details