Back

almost 3 years ago

Useful Node lambda error messages hello

  • Lambdas
  • APIs
  • Node

When I started working with lambda functions I struggled to find a simple solution to check if the correct values were present either in a JSON body or as a query parameter.

I stumbled upon a useful package on npm - node-input-validator - and this was a big step in the right direction. Here is a simple example:

simple example of validation

This only checks that there is a value for uuid in the query parameter. A more complex situation could have completely custom validation of the value as well as a custom error message:

complicated validation example

When making a mistake in calling your API, you would now get a specific error message:

custom error message

Whilst it isn't perfect, it covered my use case pretty well and has saved me time multiple times.