샘플
http-errors 2.0.0: createError
검증된 샘플 — npm http-errors 2.0.0: createError. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: assert createError creates 4xx HttpError with status…
sha256:c734337956cda8234887d3eb56b4bc560e060b46d7f564e3111db69ce3d10fd1
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 2
- 빌드한 서명 키
- 1
선언된 환경
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | SKIPPED | compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-30 |
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-30 |
케이스
HOW- 목표
- verify createError in pkg:npm/http-errors@2.0.0
- 심벌
-
- createError
- 환경
- node 22.23.2
- 생성일
- 2026-08-30T09:48:55Z
컨트랙트
- assert createError creates 4xx HttpError with status, statusCode, name, and expose true by default
- assert createError creates 5xx HttpError with expose false by default
- assert createError attaches custom properties and respects custom expose override
- assert createError wraps existing Error preserving original message and assigning status
- assert named error constructors create corresponding HttpError instances
- assert isHttpError identifies HttpError instances and rejects standard Errors or non-errors
파일
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
소스
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify createError in pkg:npm/http-errors@2.0.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/http-errors@2.0.0
Demonstrate these symbols/APIs:
- createError
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:9e00c147f97de8f2856d0c20c9c01601bf0e1085f62192757f77e3fcbff4d9cf","contract":["assert createError creates 4xx HttpError with status, statusCode, name, and expose true by default","assert createError creates 5xx HttpError with expose false by default","assert createError attaches custom properties and respects custom expose override","assert createError wraps existing Error preserving original message and assigning status","assert named error constructors create corresponding HttpError instances","assert isHttpError identifies HttpError instances and rejects standard Errors or non-errors"],"goal":"verify createError in pkg:npm/http-errors@2.0.0","kind":"HOW","packages":["pkg:npm/http-errors@2.0.0"],"schemaVersion":1,"symbols":["createError"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/http-errors@2.0.0"],"schemaVersion":1,"subject":"pkg:npm/http-errors@2.0.0","symbols":["createError"],"verifierAdapter":"node-typescript@1"}
const createError = require('http-errors');
function makeHttpError(...args) {
return createError(...args);
}
function makeClientError(status, message, props) {
if (typeof status !== 'number' || status < 400 || status >= 500) {
throw new Error('Status code must be 4xx');
}
if (props !== undefined) {
return createError(status, message, props);
}
if (message !== undefined) {
return createError(status, message);
}
return createError(status);
}
function makeServerError(status, message, props) {
if (typeof status !== 'number' || status < 500 || status >= 600) {
throw new Error('Status code must be 5xx');
}
if (props !== undefined) {
return createError(status, message, props);
}
if (message !== undefined) {
return createError(status, message);
}
return createError(status);
}
function wrapError(status, originalError) {
return createError(status, originalError);
}
function checkHttpError(err) {
return createError.isHttpError(err);
}
module.exports = {
createError,
makeHttpError,
makeClientError,
makeServerError,
wrapError,
checkHttpError,
};
{
"name": "sample-http-errors",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-http-errors",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"http-errors": "2.0.0"
}
},
"node_modules/depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/http-errors": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
"integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==",
"license": "MIT",
"dependencies": {
"depd": "2.0.0",
"inherits": "2.0.4",
"setprototypeof": "1.2.0",
"statuses": "2.0.1",
"toidentifier": "1.0.1"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"license": "ISC"
},
"node_modules/setprototypeof": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
"license": "ISC"
},
"node_modules/statuses": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
"integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/toidentifier": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
"license": "MIT",
"engines": {
"node": ">=0.6"
}
}
}
}
{
"name": "sample-http-errors",
"version": "1.0.0",
"description": "Minimal clean-room sample verifying createError in http-errors",
"main": "index.js",
"license": "MIT-0",
"dependencies": {
"http-errors": "2.0.0"
}
}
{
"schemaVersion": 1,
"goal": "verify createError in pkg:npm/http-errors@2.0.0",
"kind": "HOW",
"packages": [
"pkg:npm/http-errors@2.0.0"
],
"symbols": [
"createError"
]
}
import assert from 'node:assert';
import createError from 'http-errors';
import {
makeHttpError,
makeClientError,
makeServerError,
wrapError,
checkHttpError,
} from '../index.js';
// 1. assert createError creates 4xx HttpError with status, statusCode, name, and expose true by default
const notFoundErr = createError(404, 'Resource not found');
assert.strictEqual(notFoundErr.status, 404);
assert.strictEqual(notFoundErr.statusCode, 404);
assert.strictEqual(notFoundErr.name, 'NotFoundError');
assert.strictEqual(notFoundErr.message, 'Resource not found');
assert.strictEqual(notFoundErr.expose, true);
assert.ok(notFoundErr instanceof Error);
assert.ok(notFoundErr instanceof createError.HttpError);
assert.ok(notFoundErr instanceof createError.NotFound);
const helperClientErr = makeClientError(403, 'Forbidden access');
assert.strictEqual(helperClientErr.status, 403);
assert.strictEqual(helperClientErr.statusCode, 403);
assert.strictEqual(helperClientErr.name, 'ForbiddenError');
assert.strictEqual(helperClientErr.expose, true);
// 2. assert createError creates 5xx HttpError with expose false by default
const serverErr = createError(500, 'Internal database failure');
assert.strictEqual(serverErr.status, 500);
assert.strictEqual(serverErr.statusCode, 500);
assert.strictEqual(serverErr.name, 'InternalServerError');
assert.strictEqual(serverErr.message, 'Internal database failure');
assert.strictEqual(serverErr.expose, false);
assert.ok(serverErr instanceof createError.InternalServerError);
const helperServerErr = makeServerError(503, 'Service unavailable');
assert.strictEqual(helperServerErr.status, 503);
assert.strictEqual(helperServerErr.expose, false);
// 3. assert createError attaches custom properties and respects custom expose override
const customErr = createError(400, 'Invalid parameter payload', {
code: 'ERR_INVALID_PARAM',
field: 'username',
expose: false,
});
assert.strictEqual(customErr.status, 400);
assert.strictEqual(customErr.statusCode, 400);
assert.strictEqual(customErr.name, 'BadRequestError');
assert.strictEqual(customErr.code, 'ERR_INVALID_PARAM');
assert.strictEqual(customErr.field, 'username');
assert.strictEqual(customErr.expose, false);
const helperCustom = makeHttpError(422, 'Unprocessable entity', {
details: [{ field: 'email', reason: 'invalid format' }],
});
assert.strictEqual(helperCustom.status, 422);
assert.strictEqual(helperCustom.statusCode, 422);
assert.deepStrictEqual(helperCustom.details, [{ field: 'email', reason: 'invalid format' }]);
assert.strictEqual(helperCustom.expose, true);
// 4. assert createError wraps existing Error preserving original message and assigning status
const originalError = new Error('Connection refused');
const wrapped = wrapError(502, originalError);
assert.strictEqual(wrapped.status, 502);
assert.strictEqual(wrapped.statusCode, 502);
assert.strictEqual(wrapped.message, 'Connection refused');
assert.strictEqual(wrapped.expose, false);
assert.strictEqual(wrapped, originalError);
// 5. assert named error constructors create corresponding HttpError instances
const badRequest = new createError.BadRequest('Missing required headers');
assert.strictEqual(badRequest.status, 400);
assert.strictEqual(badRequest.statusCode, 400);
assert.strictEqual(badRequest.name, 'BadRequestError');
assert.strictEqual(badRequest.message, 'Missing required headers');
assert.strictEqual(badRequest.expose, true);
assert.ok(badRequest instanceof createError.BadRequest);
assert.ok(badRequest instanceof createError.HttpError);
assert.ok(badRequest instanceof Error);
const unauthorized = new createError.Unauthorized('Bearer token required');
assert.strictEqual(unauthorized.status, 401);
assert.strictEqual(unauthorized.statusCode, 401);
assert.strictEqual(unauthorized.name, 'UnauthorizedError');
assert.strictEqual(unauthorized.expose, true);
// 6. assert isHttpError identifies HttpError instances and rejects standard Errors or non-errors
assert.strictEqual(createError.isHttpError(notFoundErr), true);
assert.strictEqual(createError.isHttpError(badRequest), true);
assert.strictEqual(createError.isHttpError(wrapped), true);
assert.strictEqual(checkHttpError(helperServerErr), true);
assert.strictEqual(createError.isHttpError(new Error('plain error')), false);
assert.strictEqual(createError.isHttpError('string error'), false);
assert.strictEqual(createError.isHttpError(null), false);
assert.strictEqual(createError.isHttpError(undefined), false);
assert.strictEqual(createError.isHttpError({ status: 500 }), false);
console.log('All http-errors contract assertions passed.');
오리진 시더
익명