Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fastify/sensible

Package Overview
Dependencies
Maintainers
18
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/sensible - npm Package Compare versions

Comparing version 4.1.0 to 5.0.0

1

index.d.ts

@@ -64,3 +64,2 @@ import { FastifyPlugin } from 'fastify'

export interface SensibleOptions {
errorHandler?: boolean
}

@@ -67,0 +66,0 @@

@@ -52,13 +52,2 @@ 'use strict'

if (opts.errorHandler !== false) {
fastify.setErrorHandler(function (error, request, reply) {
if (reply.raw.statusCode === 500 && error.explicitInternalServerError !== true) {
request.log.error(error)
reply.send(new Error('Something went wrong'))
} else {
reply.send(error)
}
})
}
function to (promise) {

@@ -72,4 +61,4 @@ return promise.then(data => [null, data], err => [err, undefined])

module.exports = fp(fastifySensible, {
name: 'fastify-sensible',
fastify: '>=3.x'
name: '@fastify/sensible',
fastify: '4.x'
})

6

index.test-d.ts

@@ -7,5 +7,3 @@ import { expectType, expectAssignable, expectError } from 'tsd'

app.register(fastifySensible, {
errorHandler: true
})
app.register(fastifySensible)

@@ -150,2 +148,2 @@ app.get('/', (req, reply) => {

expectType<string | false | null>(req.is('foo', 'bar'))
})
})
{
"name": "@fastify/sensible",
"version": "4.1.0",
"version": "5.0.0",
"description": "Defaults for Fastify that everyone can agree on",

@@ -27,3 +27,3 @@ "main": "index.js",

"@types/node": "^17.0.0",
"fastify": "^3.0.0",
"fastify": "^4.0.0-rc.2",
"standard": "^17.0.0",

@@ -30,0 +30,0 @@ "tap": "^16.0.0",

@@ -11,3 +11,4 @@ # @fastify/sensible

Supports Fastify versions `3.x`.
Supports Fastify versions `4.x`.
Please refer to [this branch](https://github.com/fastify/fastify-sensible/tree/4.x) and related versions for Fastify `3.x` compatibility.
Please refer to [this branch](https://github.com/fastify/fastify-sensible/tree/2.x) and related versions for Fastify `2.x` compatibility.

@@ -242,9 +243,2 @@ Please refer to [this branch](https://github.com/fastify/fastify-sensible/tree/1.x) and related versions for Fastify `1.x` compatibility.

#### Custom error handler
This plugins also adds a custom error handler, which hides the error message in case of `500` errors that are being generated by throwed errors, instead it returns `Something went wrong`.<br>
This is especially useful if you are using *async* routes, where every uncaught error will be sent back to the user *(but do not worry, the original error message is logged as error in any case)*.
If needed, it can be disabled by setting the option `errorHandler` to `false`.
If you return a `500` error via the API provided on `fastify.httpErrors` and `reply` objects, the custom error message is preserved and returned in the HTTP response body.
## Contributing

@@ -261,2 +255,2 @@ Do you feel there is some utility that *everyone can agree on* which is not present?<br>

MIT
Copyright © 2018-2021 Tomas Della Vedova
Copyright © Tomas Della Vedova & Fastify collaborators

@@ -23,5 +23,5 @@ 'use strict'

t.error(err)
t.strictEqual(res.statusCode, 200)
t.strictEqual(res.headers['cache-control'], 'public')
t.strictEqual(res.payload, 'ok')
t.equal(res.statusCode, 200)
t.equal(res.headers['cache-control'], 'public')
t.equal(res.payload, 'ok')
})

@@ -49,5 +49,5 @@ })

t.error(err)
t.strictEqual(res.statusCode, 200)
t.strictEqual(res.headers['cache-control'], 'public, max-age=604800, immutable')
t.strictEqual(res.payload, 'ok')
t.equal(res.statusCode, 200)
t.equal(res.headers['cache-control'], 'public, max-age=604800, immutable')
t.equal(res.payload, 'ok')
})

@@ -71,5 +71,5 @@ })

t.error(err)
t.strictEqual(res.statusCode, 200)
t.strictEqual(res.headers['cache-control'], 'no-store, max-age=0, private')
t.strictEqual(res.payload, 'ok')
t.equal(res.statusCode, 200)
t.equal(res.headers['cache-control'], 'no-store, max-age=0, private')
t.equal(res.payload, 'ok')
})

@@ -93,5 +93,5 @@ })

t.error(err)
t.strictEqual(res.statusCode, 200)
t.strictEqual(res.headers['cache-control'], 'stale-while-revalidate=42')
t.strictEqual(res.payload, 'ok')
t.equal(res.statusCode, 200)
t.equal(res.headers['cache-control'], 'stale-while-revalidate=42')
t.equal(res.payload, 'ok')
})

@@ -118,5 +118,5 @@ })

t.error(err)
t.strictEqual(res.statusCode, 200)
t.strictEqual(res.headers['cache-control'], 'stale-while-revalidate=42, stale-if-error=1')
t.strictEqual(res.payload, 'ok')
t.equal(res.statusCode, 200)
t.equal(res.headers['cache-control'], 'stale-while-revalidate=42, stale-if-error=1')
t.equal(res.payload, 'ok')
})

@@ -146,5 +146,5 @@ })

t.error(err)
t.strictEqual(res.statusCode, 200)
t.equal(res.statusCode, 200)
t.notOk(res.headers['cache-control'])
t.strictEqual(res.payload, 'ok')
t.equal(res.payload, 'ok')
})

@@ -168,5 +168,5 @@ })

t.error(err)
t.strictEqual(res.statusCode, 200)
t.strictEqual(res.headers['cache-control'], 'max-age=0, must-revalidate')
t.strictEqual(res.payload, 'ok')
t.equal(res.statusCode, 200)
t.equal(res.headers['cache-control'], 'max-age=0, must-revalidate')
t.equal(res.payload, 'ok')
})

@@ -190,5 +190,5 @@ })

t.error(err)
t.strictEqual(res.statusCode, 200)
t.strictEqual(res.headers['cache-control'], 'public, max-age=42, immutable')
t.strictEqual(res.payload, 'ok')
t.equal(res.statusCode, 200)
t.equal(res.headers['cache-control'], 'public, max-age=42, immutable')
t.equal(res.payload, 'ok')
})

@@ -212,5 +212,5 @@ })

t.error(err)
t.strictEqual(res.statusCode, 200)
t.strictEqual(res.headers['cache-control'], 'public, max-age=42, immutable')
t.strictEqual(res.payload, 'ok')
t.equal(res.statusCode, 200)
t.equal(res.headers['cache-control'], 'public, max-age=42, immutable')
t.equal(res.payload, 'ok')
})

@@ -237,5 +237,5 @@ })

t.error(err)
t.strictEqual(res.statusCode, 200)
t.strictEqual(res.headers['cache-control'], 'max-age=42, stale-while-revalidate=3')
t.strictEqual(res.payload, 'ok')
t.equal(res.statusCode, 200)
t.equal(res.headers['cache-control'], 'max-age=42, stale-while-revalidate=3')
t.equal(res.payload, 'ok')
})

@@ -260,6 +260,6 @@ })

t.error(err)
t.strictEqual(res.statusCode, 200)
t.strictEqual(res.headers['cache-control'], 'max-age=86400')
t.strictEqual(res.payload, 'ok')
t.equal(res.statusCode, 200)
t.equal(res.headers['cache-control'], 'max-age=86400')
t.equal(res.payload, 'ok')
})
})

@@ -10,3 +10,3 @@ 'use strict'

Object.keys(statusCodes).forEach(code => {
if (Number(code) < 400) return
if (Number(code) < 400 || code === '418') return
t.test(code, t => {

@@ -28,12 +28,4 @@ t.plan(3)

t.equal(res.statusCode, Number(code))
if (code === '418') {
// https://github.com/fastify/fastify/blob/b96934d46091bb1c93f55b07149520bb9e5c0729/lib/reply.js#L350-L355
if (code === '425') {
t.same(JSON.parse(res.payload), {
error: 'I\'m a Teapot',
message: 'I\'m a Teapot',
statusCode: 418
})
// TODO should be deleted after release of https://github.com/jshttp/http-errors/pull/73
} else if (code === '425') {
t.same(JSON.parse(res.payload), {
error: 'Too Early',

@@ -58,3 +50,3 @@ message: 'Too Early',

Object.keys(statusCodes).forEach(code => {
if (Number(code) < 400) return
if (Number(code) < 400 || code === '418') return
t.test(code, t => {

@@ -74,17 +66,8 @@ t.plan(3)

t.error(err)
if (code === '418') {
t.equal(res.statusCode, 500)
t.same(JSON.parse(res.payload), {
error: 'Internal Server Error',
message: 'Something went wrong',
statusCode: 500
})
} else {
t.equal(res.statusCode, Number(code))
t.same(JSON.parse(res.payload), {
error: statusCodes[code],
message: statusCodes[code],
statusCode: Number(code)
})
}
t.equal(res.statusCode, Number(code))
t.same(JSON.parse(res.payload), {
error: statusCodes[code],
message: statusCodes[code],
statusCode: Number(code)
})
})

@@ -98,3 +81,3 @@ })

Object.keys(statusCodes).forEach(code => {
if (Number(code) < 400) return
if (Number(code) < 400 || code === '418') return
t.test(code, t => {

@@ -129,3 +112,2 @@ t.plan(3)

if (code === '414') return 'uriTooLong'
if (code === '418') return 'imateapot'
if (code === '505') return 'httpVersionNotSupported'

@@ -132,0 +114,0 @@ msg = msg.split(' ').join('').replace(/'/g, '')

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc