Skip to content

Commit

Permalink
fix!: replace unorderedCollection function with tooEarly
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Feb 21, 2022
1 parent a868060 commit d6b6e43
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 20 deletions.
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
7 changes: 0 additions & 7 deletions test/httpErrors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ test('Should generate the correct http error', t => {
// `statusCodes` uses the capital T
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
8 changes: 2 additions & 6 deletions test/httpErrorsReply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test('Should generate the correct http error', t => {
} else if (code === '425') {
t.same(JSON.parse(res.payload), {
error: node14 ? 'Too Early' : 'Unordered Collection',
message: 'Unordered Collection',
message: node14 ? 'Too Early' : 'Unordered Collection',
statusCode: 425
})
} else {
Expand Down Expand Up @@ -73,8 +73,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 (node10 && code === '418') {
t.equal(res.statusCode, 500)
t.same(JSON.parse(res.payload), {
error: 'Internal Server Error',
Expand Down Expand Up @@ -128,9 +127,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

0 comments on commit d6b6e43

Please sign in to comment.