@snyk/error-catalog-nodejs-public 5.7.1 → 5.8.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/package.json +1 -1
- package/src/problem-error.d.ts +2 -1
- package/src/problem-error.js +13 -5
- package/src/problem-error.js.map +1 -1
- package/src/types.d.ts +2 -10
- package/src/types.js.map +1 -1
package/package.json
CHANGED
package/src/problem-error.d.ts
CHANGED
|
@@ -19,9 +19,10 @@ export declare class ProblemError extends Error {
|
|
|
19
19
|
readonly detail: string;
|
|
20
20
|
readonly additionalData?: Record<string, any> | undefined;
|
|
21
21
|
readonly cause?: Error | undefined;
|
|
22
|
+
readonly logs?: string[] | undefined;
|
|
22
23
|
private readonly id;
|
|
23
24
|
readonly isErrorCatalogError = true;
|
|
24
|
-
constructor(metadata: ErrorMetadata, detail: string, additionalData?: Record<string, any> | undefined, cause?: Error | undefined);
|
|
25
|
+
constructor(metadata: ErrorMetadata, detail: string, additionalData?: Record<string, any> | undefined, cause?: Error | undefined, logs?: string[] | undefined);
|
|
25
26
|
format(instance: string, formatType: ErrorFormats): ProblemJson | JsonApi;
|
|
26
27
|
toProblemJson(instance: string): ProblemJson;
|
|
27
28
|
/**
|
package/src/problem-error.js
CHANGED
|
@@ -20,12 +20,17 @@ const types_1 = require("./types");
|
|
|
20
20
|
const uuid_1 = require("uuid");
|
|
21
21
|
const util_1 = require("./util");
|
|
22
22
|
class ProblemError extends Error {
|
|
23
|
-
constructor(metadata, detail, additionalData, cause
|
|
23
|
+
constructor(metadata, detail, additionalData, cause,
|
|
24
|
+
// Logs or tracebacks or other relevant information that should be displayed to the consumer or end-user.
|
|
25
|
+
// NOTE! These logs will be displayed to end-users and potentially customers of Snyk. They *will* be monitored by
|
|
26
|
+
// ProdSec and should therefore never contain sensitive information, neither about customer data nor Snyk infrastructure.
|
|
27
|
+
logs) {
|
|
24
28
|
super(metadata.title);
|
|
25
29
|
this.metadata = metadata;
|
|
26
30
|
this.detail = detail;
|
|
27
31
|
this.additionalData = additionalData;
|
|
28
32
|
this.cause = cause;
|
|
33
|
+
this.logs = logs;
|
|
29
34
|
// Since `instanceof` cannot be relied upon for class checks in situations where the `ProblemError` was thrown from a dependency of the executing app, we need a more viable solution.
|
|
30
35
|
// See: https://stackoverflow.com/questions/41587865/using-instanceof-on-objects-created-with-constructors-from-deep-npm-dependenci/41592087#41592087
|
|
31
36
|
this.isErrorCatalogError = true;
|
|
@@ -47,7 +52,7 @@ class ProblemError extends Error {
|
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
54
|
toProblemJson(instance) {
|
|
50
|
-
const payload = Object.assign({ type: this.metadata.type, title: this.metadata.title, status: this.metadata.status, errorCode: this.metadata.errorCode, detail: this.detail, classification: this.metadata.classification, instance }, this.additionalData);
|
|
55
|
+
const payload = Object.assign({ type: this.metadata.type, title: this.metadata.title, status: this.metadata.status, errorCode: this.metadata.errorCode, detail: this.detail, classification: this.metadata.classification, instance, logs: this.logs }, this.additionalData);
|
|
51
56
|
return new types_1.ProblemJson(payload);
|
|
52
57
|
}
|
|
53
58
|
/**
|
|
@@ -77,6 +82,9 @@ class ProblemError extends Error {
|
|
|
77
82
|
if (source) {
|
|
78
83
|
jsonApiErrorObject.source = source;
|
|
79
84
|
}
|
|
85
|
+
if (this.logs) {
|
|
86
|
+
jsonApiErrorObject.meta['logs'] = this.logs;
|
|
87
|
+
}
|
|
80
88
|
return jsonApiErrorObject;
|
|
81
89
|
}
|
|
82
90
|
toJsonApi(instance) {
|
|
@@ -89,19 +97,19 @@ class ProblemError extends Error {
|
|
|
89
97
|
return new types_1.JsonApi(payload);
|
|
90
98
|
}
|
|
91
99
|
static fromJsonApiErrorObject(obj) {
|
|
92
|
-
var _a
|
|
100
|
+
var _a;
|
|
93
101
|
const metadata = {
|
|
94
102
|
title: obj.title,
|
|
95
103
|
errorCode: obj.code,
|
|
96
104
|
type: (_a = obj.links) === null || _a === void 0 ? void 0 : _a.about,
|
|
97
105
|
status: Number(obj.status),
|
|
98
|
-
classification:
|
|
106
|
+
classification: obj.meta.classification,
|
|
99
107
|
};
|
|
100
108
|
const additionalData = Object.assign(Object.assign({}, obj.meta), {
|
|
101
109
|
// We need to add an override if we want to preserve the same id across invocations of this function,
|
|
102
110
|
// as that otherwise gets generated automatically from a UUID whenever a new ProblemError is instantiated.
|
|
103
111
|
overrideErrorId: obj.id });
|
|
104
|
-
const instance = new ProblemError(metadata, obj.detail, additionalData);
|
|
112
|
+
const instance = new ProblemError(metadata, obj.detail, additionalData, undefined, obj.meta.logs);
|
|
105
113
|
// Remove it again to ensure we don't change the signature of the incoming object
|
|
106
114
|
if (instance.additionalData && instance.additionalData['overrideErrorId']) {
|
|
107
115
|
delete instance.additionalData['overrideErrorId'];
|
package/src/problem-error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"problem-error.js","sourceRoot":"","sources":["../../../../packages/error-catalog-nodejs-public/src/problem-error.ts"],"names":[],"mappings":";;;AAAA,mCAQiB;AACjB,+BAA0B;AAC1B,iCAAiD;AAEjD,MAAa,YAAa,SAAQ,KAAK;IAOrC,YACkB,QAAuB,EACvB,MAAc,EACd,cAAoC,EACpC,KAAa;
|
|
1
|
+
{"version":3,"file":"problem-error.js","sourceRoot":"","sources":["../../../../packages/error-catalog-nodejs-public/src/problem-error.ts"],"names":[],"mappings":";;;AAAA,mCAQiB;AACjB,+BAA0B;AAC1B,iCAAiD;AAEjD,MAAa,YAAa,SAAQ,KAAK;IAOrC,YACkB,QAAuB,EACvB,MAAc,EACd,cAAoC,EACpC,KAAa;IAC7B,yGAAyG;IACzG,iHAAiH;IACjH,yHAAyH;IACzG,IAAe;QAE/B,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QATN,aAAQ,GAAR,QAAQ,CAAe;QACvB,WAAM,GAAN,MAAM,CAAQ;QACd,mBAAc,GAAd,cAAc,CAAsB;QACpC,UAAK,GAAL,KAAK,CAAQ;QAIb,SAAI,G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AE,KAAK;YACtB,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;YAC1B,cAAc,EAAE,GAAG,CAAC,IAAI,CAAC,cAAc;SACvB,CAAC;QAEnB,MAAM,cAAc,mCACf,GAAG,CAAC,IAAI;YACX,qGAAqG;YACrG,0GAA0G;YAC1G,eAAe,EAAE,GAAG,CAAC,EAAE,GACxB,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,YAAY,CAC/B,QAAQ,EACR,GAAG,CAAC,MAAM,EACV,cAAc,EACd,SAAS,EACT,GAAG,CAAC,IAAI,CAAC,IAAI,CACd,CAAC;QAEF,iFAAiF;QACjF,IAAI,QAAQ,CAAC,cAAc,IAAI,QAAQ,CAAC,cAAc,CAAC,iBAAiB,CAAC,EAAE;YACzE,OAAO,QAAQ,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;SACnD;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEM,MAAM,CAAC,WAAW,CAAC,OAAsB;QAC9C,MAAM,aAAa,GAAmB,EAAE,CAAC;QACzC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAC7B,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;QACH,OAAO,aAAa,CAAC;IACvB,CAAC;CACF;AAhJD,oCAgJC"}
|
package/src/types.d.ts
CHANGED
|
@@ -19,23 +19,14 @@ export declare enum Classification {
|
|
|
19
19
|
UNSUPPORTED = "UNSUPPORTED"
|
|
20
20
|
}
|
|
21
21
|
export type Problem = {
|
|
22
|
-
/** A URI reference that identifies the problem type. This specification encourages that, when dereferenced, it provide human-readable documentation for the problem type. */
|
|
23
22
|
type: string;
|
|
24
|
-
/** A short, human-readable summary of the problem type. This should not chance from occurrence to occurrence of the problem.*/
|
|
25
23
|
title: string;
|
|
26
|
-
/** A human-readable explanation specific to this occurrence of the problem. */
|
|
27
24
|
detail: string;
|
|
28
|
-
/** The HTTP status code generated by the origin server for this occurrence of the problem. */
|
|
29
25
|
status: number;
|
|
30
|
-
/** An internal code for the error that occurred. */
|
|
31
26
|
errorCode: string;
|
|
32
|
-
/** A URI that identifies the specific occurrence of the problem. */
|
|
33
27
|
instance?: string;
|
|
34
|
-
/** The level of this error */
|
|
35
28
|
level?: string;
|
|
36
|
-
/** Determining whether this error is a failure of Snyk to handle an operation that it was expected to, or if it derives from a requesting service producing something that cannot be handled. */
|
|
37
29
|
classification: Classification;
|
|
38
|
-
/** Additional properties. */
|
|
39
30
|
[x: string]: any;
|
|
40
31
|
};
|
|
41
32
|
export type ErrorMetadata = Pick<Problem, 'type' | 'title' | 'status' | 'errorCode' | 'level' | 'instance' | 'classification'>;
|
|
@@ -70,10 +61,11 @@ export type JsonApiErrorObject = {
|
|
|
70
61
|
title: string;
|
|
71
62
|
detail: string;
|
|
72
63
|
source?: JsonApiErrorSource;
|
|
73
|
-
meta
|
|
64
|
+
meta: {
|
|
74
65
|
[x: string]: any;
|
|
75
66
|
isErrorCatalogError: boolean;
|
|
76
67
|
classification?: Classification;
|
|
68
|
+
logs?: string[];
|
|
77
69
|
};
|
|
78
70
|
};
|
|
79
71
|
export type JsonApiErrors = {
|
package/src/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../packages/error-catalog-nodejs-public/src/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAIX;AAJD,WAAY,cAAc;IACxB,2CAAyB,CAAA;IACzB,2CAAyB,CAAA;IACzB,6CAA2B,CAAA;AAC7B,CAAC,EAJW,cAAc,8BAAd,cAAc,QAIzB;AAkCD,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,qDAAO,CAAA;IACP,6DAAW,CAAA;AACb,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB;AAQD,MAAa,WAAW;IACtB,YAA6B,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;IAAG,CAAC;IAEjD,OAAO;QACL,OAAO;YACL,cAAc,EAAE,2BAA2B;SAC5C,CAAC;IACJ,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAZD,kCAYC;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../packages/error-catalog-nodejs-public/src/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAIX;AAJD,WAAY,cAAc;IACxB,2CAAyB,CAAA;IACzB,2CAAyB,CAAA;IACzB,6CAA2B,CAAA;AAC7B,CAAC,EAJW,cAAc,8BAAd,cAAc,QAIzB;AAkCD,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,qDAAO,CAAA;IACP,6DAAW,CAAA;AACb,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB;AAQD,MAAa,WAAW;IACtB,YAA6B,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;IAAG,CAAC;IAEjD,OAAO;QACL,OAAO;YACL,cAAc,EAAE,2BAA2B;SAC5C,CAAC;IACJ,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAZD,kCAYC;AAsCD,MAAa,OAAO;IAClB,YAA6B,OAAsB;QAAtB,YAAO,GAAP,OAAO,CAAe;IAAG,CAAC;IAEvD,OAAO;QACL,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAVD,0BAUC"}
|