Lambda API v0.9 adds new features to give developers better control over error handling and serialization. A TypeScript declaration file has also been added along with some additional API Gateway inputs that are now available in the REQUEST
object.
NPM:Â https://www.npmjs.com/package/lambda-api
GitHub:Â https://github.com/jeremydaly/lambda-api
New Error Types
Lambda API now provides several different types of errors that can be used by your application. RouteError
, MethodError
, ResponseError
, and FileError
will all be passed to your error middleware. ConfigurationError
s will throw an exception when you attempt to .run()
your route and can be caught in a try/catch
block. Most error types contain additional properties that further detail the issue.
1 2 3 4 5 6 7 8 9 10 |
const errorHandler = (err,req,res,next) => { if (err.name === 'RouteError') { // do something with route error } else if (err.name === 'FileError') { // do something with file error } // continue next() }) |
Custom Serializers
By default, Lambda API will serialize objects with JSON.stringify()
. If you want more fine-grained control over serialization, you can now add a serializer
 property to the configuration options when instantiating the API.
1 2 3 4 |
const api = require('lambda-api')({ version: 'v1.0', serializer: myCustomSerializer }); |
Additional API Gateway Inputs
Lambda API now passes through additional API Gateway inputs directly into the REQUEST
 object including pathParameters
, stageVariables
and isBase64Encoded
.
TypeScript Support
Thanks to an incredible amount of work by @hassankhan, a TypeScript declaration file has been added to support your projects. Just import ‘lambda-api’ into your TypeScript handler.
1 2 3 4 5 6 7 8 |
// import Lambda API and TypeScript declarations import API from 'lambda-api' // instantiate the API const api = API({ version: 'v1', logger: { level: 'debug' } }); |
Full Release Notes:Â https://github.com/jeremydaly/lambda-api/releases/tag/v0.9.0
NPM:Â https://www.npmjs.com/package/lambda-api
GitHub:Â https://github.com/jeremydaly/lambda-api
Tags: lambda-api, typescript
Did you like this post? ð Do you want more? ð  Follow me on Twitter or check out some of the projects I’m working on.
Learn more about Lambda API or check out the other projects I'm working on.