@fastify/error 3.4.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -0
- package/.github/workflows/ci.yml +1 -1
- package/index.js +1 -1
- package/package.json +5 -4
- package/test/index.test.js +11 -1
package/.gitattributes
ADDED
package/.github/workflows/ci.yml
CHANGED
package/index.js
CHANGED
|
@@ -23,7 +23,7 @@ function createError (code, message, statusCode = 500, Base = Error) {
|
|
|
23
23
|
this.statusCode = statusCode
|
|
24
24
|
|
|
25
25
|
const lastElement = args.length - 1
|
|
26
|
-
if (lastElement !== 1 && args[lastElement] && typeof args[lastElement] === 'object' && 'cause' in args[lastElement]) {
|
|
26
|
+
if (lastElement !== -1 && args[lastElement] && typeof args[lastElement] === 'object' && 'cause' in args[lastElement]) {
|
|
27
27
|
this.cause = args.pop().cause
|
|
28
28
|
}
|
|
29
29
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/error",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "A small utility, used by Fastify itself, for generating consistent error objects across your codebase and plugins.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"type": "commonjs",
|
|
6
7
|
"types": "types/index.d.ts",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"lint": "standard",
|
|
@@ -29,9 +30,9 @@
|
|
|
29
30
|
"homepage": "https://github.com/fastify/fastify-error#readme",
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"benchmark": "^2.1.4",
|
|
32
|
-
"standard": "^17.
|
|
33
|
-
"tap": "^
|
|
34
|
-
"tsd": "^0.
|
|
33
|
+
"standard": "^17.1.0",
|
|
34
|
+
"tap": "^18.7.1",
|
|
35
|
+
"tsd": "^0.31.0"
|
|
35
36
|
},
|
|
36
37
|
"tsd": {
|
|
37
38
|
"compilerOptions": {
|
package/test/index.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const test = require('tap')
|
|
3
|
+
const { test } = require('tap')
|
|
4
4
|
const createError = require('..')
|
|
5
5
|
|
|
6
6
|
test('Create error with zero parameter', t => {
|
|
@@ -163,6 +163,16 @@ test('Create an error with cause', t => {
|
|
|
163
163
|
t.equal(err.cause, cause)
|
|
164
164
|
})
|
|
165
165
|
|
|
166
|
+
test('Create an error with cause and message', t => {
|
|
167
|
+
t.plan(2)
|
|
168
|
+
const cause = new Error('HEY')
|
|
169
|
+
const NewError = createError('CODE', 'Not available: %s')
|
|
170
|
+
const err = NewError('foo', { cause })
|
|
171
|
+
|
|
172
|
+
t.ok(err instanceof Error)
|
|
173
|
+
t.equal(err.cause, cause)
|
|
174
|
+
})
|
|
175
|
+
|
|
166
176
|
test('Create an error with last argument null', t => {
|
|
167
177
|
t.plan(2)
|
|
168
178
|
const cause = new Error('HEY')
|