Skip to content

Commit

Permalink
fix: Expose constructor in prototype when using factory
Browse files Browse the repository at this point in the history
  • Loading branch information
adriengibrat committed Mar 12, 2018
1 parent 244f6f5 commit 387cc8d
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 1 deletion.
139 changes: 139 additions & 0 deletions npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
0 info it worked if it ends with ok
1 verbose cli [ '/home/adrien/.nvm/versions/node/v6.11.3/bin/node',
1 verbose cli '/home/adrien/.nvm/versions/node/v6.11.3/bin/npm',
1 verbose cli 'publish' ]
2 info using [email protected]
3 info using [email protected]
4 verbose publish [ '.' ]
5 silly cache add args [ '.', null ]
6 verbose cache add spec .
7 silly cache add parsed spec Result {
7 silly cache add raw: '.',
7 silly cache add scope: null,
7 silly cache add escapedName: null,
7 silly cache add name: null,
7 silly cache add rawSpec: '.',
7 silly cache add spec: '/home/adrien/Documents/custom-error',
7 silly cache add type: 'directory' }
8 verbose addLocalDirectory /home/adrien/.npm/ts-custom-error/1.0.0/package.tgz not in flight; packing
9 verbose correctMkdir /home/adrien/.npm correctMkdir not in flight; initializing
10 info lifecycle [email protected]~prepublish: [email protected]
11 silly lifecycle [email protected]~prepublish: no script for prepublish, continuing
12 verbose tar pack [ '/home/adrien/.npm/ts-custom-error/1.0.0/package.tgz',
12 verbose tar pack '/home/adrien/Documents/custom-error' ]
13 verbose tarball /home/adrien/.npm/ts-custom-error/1.0.0/package.tgz
14 verbose folder /home/adrien/Documents/custom-error
15 verbose addLocalTarball adding from inside cache /home/adrien/.npm/ts-custom-error/1.0.0/package.tgz
16 verbose correctMkdir /home/adrien/.npm correctMkdir not in flight; initializing
17 silly cache afterAdd [email protected]
18 verbose afterAdd /home/adrien/.npm/ts-custom-error/1.0.0/package/package.json not in flight; writing
19 verbose correctMkdir /home/adrien/.npm correctMkdir not in flight; initializing
20 verbose afterAdd /home/adrien/.npm/ts-custom-error/1.0.0/package/package.json written
21 silly publish { name: 'ts-custom-error',
21 silly publish version: '1.0.0',
21 silly publish description: 'Extend native Error to create custom errors',
21 silly publish repository:
21 silly publish { type: 'git',
21 silly publish url: 'git+https://github.com/adriengibrat/ts-custom-error.git' },
21 silly publish bugs: { url: 'https://github.com/adriengibrat/ts-custom-error/issues' },
21 silly publish keywords: [ 'custom Error', 'extend', 'native Error' ],
21 silly publish author: { name: 'Adrien Gibrat', email: '[email protected]' },
21 silly publish license: 'WTFPL',
21 silly publish main: 'dist/custom-error.js',
21 silly publish module: 'dist/custom-error.mjs',
21 silly publish browser: 'dist/custom-error.umd.js',
21 silly publish types: 'dist/index.d.ts',
21 silly publish source: 'src/index.ts',
21 silly publish scripts:
21 silly publish { start: 'jest --watch --notify',
21 silly publish prebundle: 'rm --recursive --force dist',
21 silly publish bundle: 'microbundle --compress false',
21 silly publish test: 'jest --notify',
21 silly publish coverage: 'jest --coverage',
21 silly publish pretty: 'prettier --use-tabs --no-semi --single-quote --trailing-comma all --write src/* src/*/*',
21 silly publish precommit: 'lint-staged && npm test -- --onlyChanged',
21 silly publish prepublishOnly: 'npm test && npm run bundle' },
21 silly publish 'lint-staged': { '*.ts': [ 'npm run pretty', 'git add' ] },
21 silly publish jest:
21 silly publish { reporters: [ 'jest-tap-reporter' ],
21 silly publish transform: { '^.+\.tsx?$': 'ts-jest' },
21 silly publish testRegex: '\\.spec\\.ts$',
21 silly publish moduleFileExtensions: [ 'ts', 'js' ],
21 silly publish globals: { 'ts-jest': [Object] } },
21 silly publish devDependencies:
21 silly publish { '@types/jest': '^22.2.0',
21 silly publish husky: '^0.14.3',
21 silly publish jest: '^22.4.2',
21 silly publish 'jest-tap-reporter': '^1.9.0',
21 silly publish 'lint-staged': '^7.0.0',
21 silly publish microbundle: '^0.4.4',
21 silly publish prettier: '^1.11.1',
21 silly publish 'tap-notify': '^1.0.0',
21 silly publish 'ts-jest': '^22.4.1',
21 silly publish typescript: '^2.7.2' },
21 silly publish readme: '# ts-custom-error\n\n<!-- [![Build Status](https://travis-ci.org/adriengibrat/ts-custom-error.svg)](https://travis-ci.org/adriengibrat/ts-custom-error) -->\n\n[![NPM version](https://badge.fury.io/js/ts-custom-error.svg)](http://badge.fury.io/js/ts-custom-error)\n[![Dependency Status](https://david-dm.org/adriengibrat/ts-custom-error.svg)](https://david-dm.org/adriengibrat/ts-custom-error)\n[![devDependency Status](https://david-dm.org/adriengibrat/ts-custom-error/dev-status.svg)](https://david-dm.org/adriengibrat/ts-custom-error#info=devDependencies)\n\n## Extend native Error to create custom errors\n\nCustomError allow to easyly extends native Error in Typescript\n\n### Using a class\n```ts\nimport { CustomError } from \'ts-custom-error\'\n\nclass HttpError extends CustomError {\n\tpublic constructor(\n\t\tpublic code: number,\n\t\tmessage?: string,\n\t) {\n\t\tsuper(message)\n\t}\n}\n\n...\nnew HttpError(404, \'Not found\')\n```\n\n### Using the factory\n```ts\nimport { factory } from \'ts-custom-error\'\n\nconst HttpError = factory(function (code, message= \'\') {\n\tthis.code = code\n\tthis.message = message\n})\n\n...\nnew HttpError(404, \'Not found\')\n// or\nHttpError(404, \'Not found\')\n```\n\n## Similar packages\n- [![custom-error](https://badge.fury.io/js/custom-error.svg)](https://www.npmjs.com/package/custom-error) [custom-error](https://github.com/andrezsanchez/custom-error)\n- [![custom-errors](https://badge.fury.io/js/custom-errors.svg)](https://www.npmjs.com/package/custom-errors) [custom-errors](https://github.com/techjacker/custom-errors)\n- [![custom-error-generator](https://badge.fury.io/js/custom-error-generator.svg)](https://www.npmjs.com/package/custom-error-generator) [custom-error-generator](https://github.com/jproulx/node-custom-error)\n- [![custom-error-instance](https://badge.fury.io/js/custom-error-instance.svg)](https://www.npmjs.com/package/custom-error-instance) [custom-error-instance](https://github.com/Gi60s/custom-error-instance)\n- [![node-custom-errors](https://badge.fury.io/js/node-custom-errors.svg)](https://www.npmjs.com/package/node-custom-errors) [node-custom-errors](https://github.com/axyjs/node-custom-errors)\n- [![extendable-error](https://badge.fury.io/js/extendable-error.svg)](https://www.npmjs.com/package/extendable-error) [extendable-error](https://github.com/vilic/extendable-error)\n- [![extendable-error-class](https://badge.fury.io/js/extendable-error-class.svg)](https://www.npmjs.com/package/extendable-error-class) [extendable-error-class](https://github.com/brillout/extendable-error-class)\n- [![extend-error](https://badge.fury.io/js/extend-error.svg)](https://www.npmjs.com/package/extend-error) [extend-error](https://github.com/jayyvis/extend-error)\n- [![error-extend](https://badge.fury.io/js/eerror-extend.svg)](https://www.npmjs.com/package/error-extend) [error-extend](https://github.com/tilap/error-extend)\n',
21 silly publish readmeFilename: 'README.md',
21 silly publish gitHead: '244f6f5fb52702e34ec1924f117e9c2a4c332c6e',
21 silly publish homepage: 'https://github.com/adriengibrat/ts-custom-error#readme',
21 silly publish _id: '[email protected]',
21 silly publish _shasum: 'a0f56b3807d3eb74ebb6bf9665f32200cd1b985e',
21 silly publish _from: '.' }
22 verbose getPublishConfig undefined
23 silly mapToRegistry name ts-custom-error
24 silly mapToRegistry using default registry
25 silly mapToRegistry registry https://registry.npmjs.org/
26 silly mapToRegistry data Result {
26 silly mapToRegistry raw: 'ts-custom-error',
26 silly mapToRegistry scope: null,
26 silly mapToRegistry escapedName: 'ts-custom-error',
26 silly mapToRegistry name: 'ts-custom-error',
26 silly mapToRegistry rawSpec: '',
26 silly mapToRegistry spec: 'latest',
26 silly mapToRegistry type: 'tag' }
27 silly mapToRegistry uri https://registry.npmjs.org/ts-custom-error
28 verbose publish registryBase https://registry.npmjs.org/
29 silly publish uploading /home/adrien/.npm/ts-custom-error/1.0.0/package.tgz
30 verbose request uri https://registry.npmjs.org/ts-custom-error
31 verbose request sending authorization for write operation
32 info attempt registry request try #1 at 11:38:18 PM
33 verbose request using bearer token for auth
34 verbose request id 7b6c3ccd88a27cd4
35 http request PUT https://registry.npmjs.org/ts-custom-error
36 http 403 https://registry.npmjs.org/ts-custom-error
37 verbose headers { 'content-type': 'application/json',
37 verbose headers 'cache-control': 'max-age=300',
37 verbose headers 'content-length': '77',
37 verbose headers 'accept-ranges': 'bytes',
37 verbose headers date: 'Mon, 12 Mar 2018 22:38:20 GMT',
37 verbose headers via: '1.1 varnish',
37 verbose headers connection: 'keep-alive',
37 verbose headers 'x-served-by': 'cache-lcy19244-LCY',
37 verbose headers 'x-cache': 'MISS',
37 verbose headers 'x-cache-hits': '0',
37 verbose headers 'x-timer': 'S1520894299.775126,VS0,VE1470',
37 verbose headers vary: 'Accept-Encoding, Accept' }
38 verbose request invalidating /home/adrien/.npm/registry.npmjs.org/ts-custom-error on PUT
39 error publish Failed PUT 403
40 verbose stack Error: ts-custom-error cannot be republished until 24 hours have passed. : ts-custom-error
40 verbose stack at makeError (/home/adrien/.nvm/versions/node/v6.11.3/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:302:12)
40 verbose stack at CachingRegistryClient.<anonymous> (/home/adrien/.nvm/versions/node/v6.11.3/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:290:14)
40 verbose stack at Request._callback (/home/adrien/.nvm/versions/node/v6.11.3/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:210:14)
40 verbose stack at Request.self.callback (/home/adrien/.nvm/versions/node/v6.11.3/lib/node_modules/npm/node_modules/request/request.js:187:22)
40 verbose stack at emitTwo (events.js:106:13)
40 verbose stack at Request.emit (events.js:191:7)
40 verbose stack at Request.<anonymous> (/home/adrien/.nvm/versions/node/v6.11.3/lib/node_modules/npm/node_modules/request/request.js:1048:10)
40 verbose stack at emitOne (events.js:96:13)
40 verbose stack at Request.emit (events.js:188:7)
40 verbose stack at IncomingMessage.<anonymous> (/home/adrien/.nvm/versions/node/v6.11.3/lib/node_modules/npm/node_modules/request/request.js:969:12)
41 verbose statusCode 403
42 verbose pkgid ts-custom-error
43 verbose cwd /home/adrien/Documents/custom-error
44 error Linux 3.13.0-24-generic
45 error argv "/home/adrien/.nvm/versions/node/v6.11.3/bin/node" "/home/adrien/.nvm/versions/node/v6.11.3/bin/npm" "publish"
46 error node v6.11.3
47 error npm v3.10.10
48 error code E403
49 error ts-custom-error cannot be republished until 24 hours have passed. : ts-custom-error
50 error If you need help, you may report this error at:
50 error <https://github.com/npm/npm/issues>
51 verbose exit [ 1, true ]
10 changes: 9 additions & 1 deletion src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export function factory<Properties = CustomError>(
}

return Object.defineProperties(CustomError, {
prototype: { value: Object.create(parent.prototype) },
prototype: {
value: Object.create(parent.prototype, {
constructor: {
value: CustomError,
writable: true,
configurable: true,
},
}),
},
})
}

0 comments on commit 387cc8d

Please sign in to comment.