Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps)!: bump http-errors from 1.8.1 to 2.0.0 #97

Merged
merged 4 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ jobs:
strategy:
matrix:
node-version:
- 10
- 12
- 14
- 16
os:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const notFoundErr = fastify.httpErrors.notFound('custom message')
- <code>fastify.httpErrors.<b>unprocessableEntity()</b></code>
- <code>fastify.httpErrors.<b>locked()</b></code>
- <code>fastify.httpErrors.<b>failedDependency()</b></code>
- <code>fastify.httpErrors.<b>unorderedCollection()</b></code>
- <code>fastify.httpErrors.<b>tooEarly()</b></code>
- <code>fastify.httpErrors.<b>upgradeRequired()</b></code>
- <code>fastify.httpErrors.<b>preconditionRequired()</b></code>
- <code>fastify.httpErrors.<b>tooManyRequests()</b></code>
Expand Down
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ app.get('/', (req, reply) => {
expectAssignable<void>(reply.unprocessableEntity())
expectAssignable<void>(reply.locked())
expectAssignable<void>(reply.failedDependency())
expectAssignable<void>(reply.unorderedCollection())
expectAssignable<void>(reply.tooEarly())
expectAssignable<void>(reply.upgradeRequired())
expectAssignable<void>(reply.preconditionFailed())
expectAssignable<void>(reply.tooManyRequests())
Expand Down Expand Up @@ -80,7 +80,7 @@ app.get('/', async (req, reply) => {
expectAssignable<Error>(app.httpErrors.unprocessableEntity())
expectAssignable<Error>(app.httpErrors.locked())
expectAssignable<Error>(app.httpErrors.failedDependency())
expectAssignable<Error>(app.httpErrors.unorderedCollection())
expectAssignable<Error>(app.httpErrors.tooEarly())
expectAssignable<Error>(app.httpErrors.upgradeRequired())
expectAssignable<Error>(app.httpErrors.preconditionFailed())
expectAssignable<Error>(app.httpErrors.tooManyRequests())
Expand Down
4 changes: 2 additions & 2 deletions lib/httpError.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type HttpErrorCodes = 400 | '400' // BadRequest
| 422 | '422' // UnprocessableEntity
| 423 | '423' // Locked
| 424 | '424' // FailedDependency
| 425 | '425' // UnorderedCollection
| 425 | '425' // TooEarly
| 426 | '426' // UpgradeRequired
| 428 | '428' // PreconditionRequired
| 429 | '429' // TooManyRequests
Expand Down Expand Up @@ -75,7 +75,7 @@ type HttpErrorNames = 'badRequest'
| 'unprocessableEntity'
| 'locked'
| 'failedDependency'
| 'unorderedCollection'
| 'tooEarly'
| 'upgradeRequired'
| 'preconditionRequired'
| 'tooManyRequests'
Expand Down
4 changes: 2 additions & 2 deletions lib/httpErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ const httpErrors = {
return new createError.FailedDependency(message)
},

unorderedCollection: function unorderedCollection (message) {
return new createError.UnorderedCollection(message)
tooEarly: function tooEarly (message) {
return new createError.TooEarly(message)
},

upgradeRequired: function upgradeRequired (message) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"fast-deep-equal": "^3.1.1",
"fastify-plugin": "^3.0.0",
"forwarded": "^0.2.0",
"http-errors": "^1.7.3",
"http-errors": "^2.0.0",
"type-is": "^1.6.18",
"vary": "^1.1.2"
},
Expand Down
9 changes: 1 addition & 8 deletions test/httpErrors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ test('Should generate the correct http error', t => {
const err = fastify.httpErrors[name]()
t.ok(err instanceof HttpError)
// `statusCodes` uses the capital T
if (err.message === 'I\'m a teapot') {
if (err.message === 'I\'m a Teapot') {
t.equal(err.statusCode, 418)
// `statusCodes` uses unsupported Unordered Collection
// TODO should be deleted after release of https://github.com/jshttp/http-errors/pull/73
} else if (err.message === 'Unordered Collection') {
t.equal(err.statusCode, 425)
} else {
t.equal(err.message, statusCodes[code])
}
Expand Down Expand Up @@ -88,9 +84,6 @@ test('Should generate the correct http error (with custom message)', t => {
function normalize (code, msg) {
if (code === '414') return 'uriTooLong'
if (code === '418') return 'imateapot'
// rename of supported tooEarly to the unsupported unorderedCollection
// TODO should be deleted after release of https://github.com/jshttp/http-errors/pull/73
if (code === '425') return 'unorderedCollection'
if (code === '505') return 'httpVersionNotSupported'
msg = msg.split(' ').join('').replace(/'/g, '')
msg = msg[0].toLowerCase() + msg.slice(1)
Expand Down
19 changes: 5 additions & 14 deletions test/httpErrorsReply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ const statusCodes = require('http').STATUS_CODES
const Fastify = require('fastify')
const Sensible = require('../index')

// from Node.js v10 and above the 418 message has been changed
const node10 = Number(process.versions.node.split('.')[0]) >= 10
// from Node.js v14 and above the 425 message has been changed
const node14 = Number(process.versions.node.split('.')[0]) >= 14

test('Should generate the correct http error', t => {
Object.keys(statusCodes).forEach(code => {
if (Number(code) < 400) return
Expand All @@ -32,15 +27,15 @@ test('Should generate the correct http error', t => {
if (code === '418') {
// https://github.com/fastify/fastify/blob/b96934d46091bb1c93f55b07149520bb9e5c0729/lib/reply.js#L350-L355
t.same(JSON.parse(res.payload), {
error: node10 ? 'I\'m a Teapot' : 'I\'m a teapot',
message: 'I\'m a teapot',
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: node14 ? 'Too Early' : 'Unordered Collection',
message: 'Unordered Collection',
error: 'Too Early',
message: 'Too Early',
statusCode: 425
})
} else {
Expand Down Expand Up @@ -73,8 +68,7 @@ test('Should generate the correct http error using getter', t => {
url: '/'
}, (err, res) => {
t.error(err)
// TODO should be deleted after release of https://github.com/jshttp/http-errors/pull/73
if ((node10 && code === '418') || (node14 && code === '425')) {
if (code === '418') {
t.equal(res.statusCode, 500)
t.same(JSON.parse(res.payload), {
error: 'Internal Server Error',
Expand Down Expand Up @@ -128,9 +122,6 @@ test('Should generate the correct http error (with custom message)', t => {
function normalize (code, msg) {
if (code === '414') return 'uriTooLong'
if (code === '418') return 'imateapot'
// rename of supported tooEarly to the unsupported unorderedCollection
// TODO should be deleted after release of https://github.com/jshttp/http-errors/pull/73
if (code === '425') return 'unorderedCollection'
if (code === '505') return 'httpVersionNotSupported'
msg = msg.split(' ').join('').replace(/'/g, '')
msg = msg[0].toLowerCase() + msg.slice(1)
Expand Down