@pnpm/error
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -10,4 +10,17 @@ export default class PnpmError extends Error { | ||
constructor(code: string, message: string, opts?: { | ||
hint: string; | ||
hint?: string; | ||
}); | ||
} | ||
export declare type FetchErrorResponse = { | ||
status: number; | ||
statusText: string; | ||
}; | ||
export declare type FetchErrorRequest = { | ||
url: string; | ||
authHeaderValue?: string; | ||
}; | ||
export declare class FetchError extends PnpmError { | ||
readonly response: FetchErrorResponse; | ||
readonly request: FetchErrorRequest; | ||
constructor(request: FetchErrorRequest, response: FetchErrorResponse, hint?: string); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FetchError = void 0; | ||
class PnpmError extends Error { | ||
@@ -11,2 +12,26 @@ constructor(code, message, opts) { | ||
exports.default = PnpmError; | ||
class FetchError extends PnpmError { | ||
constructor(request, response, hint) { | ||
let message = `GET ${request.url}: ${response.statusText} - ${response.status}`; | ||
const authHeaderValue = request.authHeaderValue | ||
? hideAuthInformation(request.authHeaderValue) : undefined; | ||
if (response.status === 401 || response.status === 403) { | ||
hint = hint ? `${hint}\n\n` : ''; | ||
if (authHeaderValue) { | ||
hint += `An authorization header was used: ${authHeaderValue}`; | ||
} | ||
else { | ||
hint += `No authorization header was set for the request.`; | ||
} | ||
} | ||
super(`FETCH_${response.status}`, message, { hint }); | ||
this.request = request; | ||
this.response = response; | ||
} | ||
} | ||
exports.FetchError = FetchError; | ||
function hideAuthInformation(authHeaderValue) { | ||
const [authType, token] = authHeaderValue.split(' '); | ||
return `${authType} ${token.substring(0, 4)}[hidden]`; | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@pnpm/error", | ||
"version": "1.2.0", | ||
"description": "An error class for pnpm errors", | ||
"main": "lib/index.js", | ||
"typings": "lib/index.d.ts", | ||
"files": [ | ||
"lib", | ||
"!*.map" | ||
], | ||
"engines": { | ||
"node": ">=10.13" | ||
}, | ||
"scripts": { | ||
"lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", | ||
"test": "pnpm run compile", | ||
"prepublishOnly": "pnpm run compile", | ||
"compile": "rimraf lib tsconfig.tsbuildinfo && tsc --build" | ||
}, | ||
"repository": "https://github.com/pnpm/pnpm/blob/master/packages/error", | ||
"keywords": [ | ||
"pnpm", | ||
"error" | ||
], | ||
"author": "Zoltan Kochan <z@kochan.io> (https://www.kochan.io/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/pnpm/pnpm/issues" | ||
}, | ||
"homepage": "https://github.com/pnpm/pnpm/blob/master/packages/error#readme" | ||
"name": "@pnpm/error", | ||
"version": "1.3.0", | ||
"description": "An error class for pnpm errors", | ||
"main": "lib/index.js", | ||
"typings": "lib/index.d.ts", | ||
"files": [ | ||
"lib", | ||
"!*.map" | ||
], | ||
"engines": { | ||
"node": ">=10.13" | ||
}, | ||
"scripts": { | ||
"lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", | ||
"test": "pnpm run compile", | ||
"prepublishOnly": "pnpm run compile", | ||
"compile": "rimraf lib tsconfig.tsbuildinfo && tsc --build" | ||
}, | ||
"repository": "https://github.com/pnpm/pnpm/blob/master/packages/error", | ||
"keywords": [ | ||
"pnpm", | ||
"error" | ||
], | ||
"author": "Zoltan Kochan <z@kochan.io> (https://www.kochan.io/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/pnpm/pnpm/issues" | ||
}, | ||
"homepage": "https://github.com/pnpm/pnpm/blob/master/packages/error#readme", | ||
"funding": "https://opencollective.com/pnpm" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4796
6
60