Gathering detailed insights and metrics for middy-middleware-json-error-handler
Gathering detailed insights and metrics for middy-middleware-json-error-handler
Gathering detailed insights and metrics for middy-middleware-json-error-handler
Gathering detailed insights and metrics for middy-middleware-json-error-handler
npm install middy-middleware-json-error-handler
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
30 Stars
400 Commits
6 Forks
3 Watching
6 Branches
4 Contributors
Updated on 25 Nov 2024
TypeScript (83.98%)
JavaScript (16.02%)
Cumulative downloads
Total Downloads
Last day
39.4%
970
Compared to previous day
Last week
12%
4,682
Compared to previous week
Last month
8.4%
18,168
Compared to previous month
Last year
57.9%
205,526
Compared to previous year
3
1
41
A middy middleware that returns errors as http errors, compatible with http-errors.
Download node at nodejs.org and install it, if you haven't already.
1npm install middy-middleware-json-error-handler --save
There is additional documentation.
1import middy from '@middy/core' 2import JSONErrorHandlerMiddleware from 'middy-middleware-json-error-handler' 3import createHttpError from 'http-errors' 4import { APIGatewayEvent } from 'aws-lambda' 5 6// This is your AWS handler 7async function helloWorld (event: APIGatewayEvent) { 8 if (event.queryStringParameters?.search == null) { 9 // If you throw an error with status code, the error will be returned as stringified JSON. 10 // Only the stack will be omitted. 11 throw createHttpError(400, 'Query has to include a search') 12 } 13 14 if (event.queryStringParameters?.search === 'error') { 15 // If you throw an error with status code greater than 500 and specify in options that the error 16 // must be exposed, then the error will be returned as stringified JSON 17 throw createHttpError(500, 'Something went wrong', { expose: true }) 18 } 19 20 // If you throw an error with no status code, only a generic message will be shown to the user 21 // instead of the full error 22 throw new Error('Search is not implemented yet') 23} 24 25// Specify which are the error properties to omit in response (by default, only the stack is omitted) 26const options = { 27 errorPropertiesToOmit: ['name', 'statusCode', 'stack'] 28} 29 30// Let's "middyfy" our handler, then we will be able to attach middlewares to it (options parameter is optional) 31export const handler = middy(helloWorld) 32 .use(JSONErrorHandlerMiddleware(options)) // This middleware is needed do handle the errors thrown by the handler
No vulnerabilities found.
Reason
17 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
6 existing vulnerabilities detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 0/1 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More@middy/http-error-handler
Http error handler middleware for the middy framework
@middy/http-json-body-parser
Http JSON body parser middleware for the middy framework
@middy/http-event-normalizer
Http event normalizer middleware for the middy framework
@schibsted/middy-error-handler
Middy middleware for adding caching headers to success response and errors