diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3061648..1ebb300 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,8 +14,6 @@ jobs: strategy: matrix: node-version: - - 10 - - 12 - 14 - 16 os: diff --git a/README.md b/README.md index 398de8c..d2f07c0 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ const notFoundErr = fastify.httpErrors.notFound('custom message') - fastify.httpErrors.unprocessableEntity() - fastify.httpErrors.locked() - fastify.httpErrors.failedDependency() -- fastify.httpErrors.unorderedCollection() +- fastify.httpErrors.tooEarly() - fastify.httpErrors.upgradeRequired() - fastify.httpErrors.preconditionRequired() - fastify.httpErrors.tooManyRequests() diff --git a/index.test-d.ts b/index.test-d.ts index c4a4800..7ab47f4 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -30,7 +30,7 @@ app.get('/', (req, reply) => { expectAssignable(reply.unprocessableEntity()) expectAssignable(reply.locked()) expectAssignable(reply.failedDependency()) - expectAssignable(reply.unorderedCollection()) + expectAssignable(reply.tooEarly()) expectAssignable(reply.upgradeRequired()) expectAssignable(reply.preconditionFailed()) expectAssignable(reply.tooManyRequests()) @@ -80,7 +80,7 @@ app.get('/', async (req, reply) => { expectAssignable(app.httpErrors.unprocessableEntity()) expectAssignable(app.httpErrors.locked()) expectAssignable(app.httpErrors.failedDependency()) - expectAssignable(app.httpErrors.unorderedCollection()) + expectAssignable(app.httpErrors.tooEarly()) expectAssignable(app.httpErrors.upgradeRequired()) expectAssignable(app.httpErrors.preconditionFailed()) expectAssignable(app.httpErrors.tooManyRequests()) diff --git a/lib/httpError.d.ts b/lib/httpError.d.ts index 39bd8f7..196569b 100644 --- a/lib/httpError.d.ts +++ b/lib/httpError.d.ts @@ -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 @@ -75,7 +75,7 @@ type HttpErrorNames = 'badRequest' | 'unprocessableEntity' | 'locked' | 'failedDependency' - | 'unorderedCollection' + | 'tooEarly' | 'upgradeRequired' | 'preconditionRequired' | 'tooManyRequests' diff --git a/lib/httpErrors.js b/lib/httpErrors.js index a032d5d..f2dccab 100644 --- a/lib/httpErrors.js +++ b/lib/httpErrors.js @@ -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) { diff --git a/package.json b/package.json index 93ab9c7..938f6b3 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/httpErrors.test.js b/test/httpErrors.test.js index 9ed3612..2cf3de8 100644 --- a/test/httpErrors.test.js +++ b/test/httpErrors.test.js @@ -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]) } @@ -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) diff --git a/test/httpErrorsReply.test.js b/test/httpErrorsReply.test.js index 9d7dce9..69de901 100644 --- a/test/httpErrorsReply.test.js +++ b/test/httpErrorsReply.test.js @@ -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 @@ -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 { @@ -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', @@ -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)