@fastify/error 3.4.0 → 3.4.1

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 ADDED
@@ -0,0 +1,2 @@
1
+ # Set default behavior to automatically convert line endings
2
+ * text=auto eol=lf
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.4.0",
3
+ "version": "3.4.1",
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",
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const test = require('tap').test
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')