Installations
npm install middy-middleware-json-error-handler
Developer
dbartholomae
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
16.16.0
NPM Version
8.11.0
Statistics
30 Stars
400 Commits
6 Forks
3 Watching
6 Branches
4 Contributors
Updated on 25 Nov 2024
Languages
TypeScript (83.98%)
JavaScript (16.02%)
Total Downloads
Cumulative downloads
Total Downloads
436,507
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Peer Dependencies
1
Dev Dependencies
41
middy-middleware-json-error-handler
A middy middleware that returns errors as http errors, compatible with http-errors.
Installation
Download node at nodejs.org and install it, if you haven't already.
1npm install middy-middleware-json-error-handler --save
Documentation
There is additional documentation.
Usage
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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
6 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-w5p7-h5w8-2hfq
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/build.yml:1
- Warn: no topLevel permission defined: .github/workflows/close-stale-issues.yml:1
- Warn: no topLevel permission defined: .github/workflows/update-labels.yml:1
- Info: no jobLevel write permissions found
Reason
Found 0/1 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/dbartholomae/middy-middleware-json-error-handler/build.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/dbartholomae/middy-middleware-json-error-handler/build.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/dbartholomae/middy-middleware-json-error-handler/build.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/dbartholomae/middy-middleware-json-error-handler/build.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/dbartholomae/middy-middleware-json-error-handler/build.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:53: update your workflow using https://app.stepsecurity.io/secureworkflow/dbartholomae/middy-middleware-json-error-handler/build.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:55: update your workflow using https://app.stepsecurity.io/secureworkflow/dbartholomae/middy-middleware-json-error-handler/build.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:59: update your workflow using https://app.stepsecurity.io/secureworkflow/dbartholomae/middy-middleware-json-error-handler/build.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:73: update your workflow using https://app.stepsecurity.io/secureworkflow/dbartholomae/middy-middleware-json-error-handler/build.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/close-stale-issues.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/dbartholomae/middy-middleware-json-error-handler/close-stale-issues.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/update-labels.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/dbartholomae/middy-middleware-json-error-handler/update-labels.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/update-labels.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/dbartholomae/middy-middleware-json-error-handler/update-labels.yml/main?enable=pin
- Info: 0 out of 6 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 6 third-party GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 29 are checked with a SAST tool
Score
3.8
/10
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 MoreOther packages similar to middy-middleware-json-error-handler
@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