@axinom/mosaic-service-common 0.36.0-rc.8 → 0.36.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/dist/common/errors/default-pg-error-mapper.d.ts.map +1 -1
- package/dist/common/errors/default-pg-error-mapper.js.map +1 -1
- package/dist/common/errors/graphql-errors-customization.d.ts +34 -0
- package/dist/common/errors/graphql-errors-customization.d.ts.map +1 -0
- package/dist/common/errors/graphql-errors-customization.js +83 -0
- package/dist/common/errors/graphql-errors-customization.js.map +1 -0
- package/dist/common/errors/index.d.ts +1 -1
- package/dist/common/errors/index.d.ts.map +1 -1
- package/dist/common/errors/index.js +1 -1
- package/dist/common/errors/index.js.map +1 -1
- package/dist/common/errors/types/models.d.ts +84 -1
- package/dist/common/errors/types/models.d.ts.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/middleware/http-server-with-websockets-middleware.d.ts +2 -2
- package/dist/middleware/http-server-with-websockets-middleware.d.ts.map +1 -1
- package/dist/middleware/http-server-with-websockets-middleware.js.map +1 -1
- package/package.json +3 -8
- package/src/common/errors/default-pg-error-mapper.ts +1 -2
- package/src/common/errors/graphql-errors-customization.spec.ts +219 -0
- package/src/common/errors/graphql-errors-customization.ts +146 -0
- package/src/common/errors/index.ts +1 -1
- package/src/common/errors/types/models.ts +95 -1
- package/src/index.ts +0 -2
- package/src/middleware/http-server-with-websockets-middleware.ts +6 -2
- package/dist/common/errors/graphql-errors-handler.d.ts +0 -23
- package/dist/common/errors/graphql-errors-handler.d.ts.map +0 -1
- package/dist/common/errors/graphql-errors-handler.js +0 -127
- package/dist/common/errors/graphql-errors-handler.js.map +0 -1
- package/dist/plugins/add-error-codes-enum-plugin.d.ts +0 -23
- package/dist/plugins/add-error-codes-enum-plugin.d.ts.map +0 -1
- package/dist/plugins/add-error-codes-enum-plugin.js +0 -85
- package/dist/plugins/add-error-codes-enum-plugin.js.map +0 -1
- package/dist/plugins/annotate-types-with-permissions-plugin.d.ts +0 -22
- package/dist/plugins/annotate-types-with-permissions-plugin.d.ts.map +0 -1
- package/dist/plugins/annotate-types-with-permissions-plugin.js +0 -145
- package/dist/plugins/annotate-types-with-permissions-plugin.js.map +0 -1
- package/dist/plugins/deprecate-stray-node-id-fields-plugin.d.ts +0 -14
- package/dist/plugins/deprecate-stray-node-id-fields-plugin.d.ts.map +0 -1
- package/dist/plugins/deprecate-stray-node-id-fields-plugin.js +0 -37
- package/dist/plugins/deprecate-stray-node-id-fields-plugin.js.map +0 -1
- package/dist/plugins/generic-bulk-plugin-factory.d.ts +0 -49
- package/dist/plugins/generic-bulk-plugin-factory.d.ts.map +0 -1
- package/dist/plugins/generic-bulk-plugin-factory.js +0 -181
- package/dist/plugins/generic-bulk-plugin-factory.js.map +0 -1
- package/dist/plugins/graphiql-dark-mode-plugin-hook.d.ts +0 -13
- package/dist/plugins/graphiql-dark-mode-plugin-hook.d.ts.map +0 -1
- package/dist/plugins/graphiql-dark-mode-plugin-hook.js +0 -222
- package/dist/plugins/graphiql-dark-mode-plugin-hook.js.map +0 -1
- package/dist/plugins/graphiql-management-mode-plugin-hook.d.ts +0 -13
- package/dist/plugins/graphiql-management-mode-plugin-hook.d.ts.map +0 -1
- package/dist/plugins/graphiql-management-mode-plugin-hook.js +0 -44
- package/dist/plugins/graphiql-management-mode-plugin-hook.js.map +0 -1
- package/dist/plugins/index.d.ts +0 -11
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/index.js +0 -27
- package/dist/plugins/index.js.map +0 -1
- package/dist/plugins/omit-from-query-root-plugin.d.ts +0 -17
- package/dist/plugins/omit-from-query-root-plugin.d.ts.map +0 -1
- package/dist/plugins/omit-from-query-root-plugin.js +0 -43
- package/dist/plugins/omit-from-query-root-plugin.js.map +0 -1
- package/dist/plugins/operations-enum-generator-plugin-factory.d.ts +0 -15
- package/dist/plugins/operations-enum-generator-plugin-factory.d.ts.map +0 -1
- package/dist/plugins/operations-enum-generator-plugin-factory.js +0 -108
- package/dist/plugins/operations-enum-generator-plugin-factory.js.map +0 -1
- package/dist/plugins/subscriptions-plugin-factory.d.ts +0 -9
- package/dist/plugins/subscriptions-plugin-factory.d.ts.map +0 -1
- package/dist/plugins/subscriptions-plugin-factory.js +0 -67
- package/dist/plugins/subscriptions-plugin-factory.js.map +0 -1
- package/dist/plugins/validation-directives-plugin.d.ts +0 -6
- package/dist/plugins/validation-directives-plugin.d.ts.map +0 -1
- package/dist/plugins/validation-directives-plugin.js +0 -117
- package/dist/plugins/validation-directives-plugin.js.map +0 -1
- package/dist/postgraphile/index.d.ts +0 -3
- package/dist/postgraphile/index.d.ts.map +0 -1
- package/dist/postgraphile/index.js +0 -19
- package/dist/postgraphile/index.js.map +0 -1
- package/dist/postgraphile/postgraphile-options-builder.d.ts +0 -270
- package/dist/postgraphile/postgraphile-options-builder.d.ts.map +0 -1
- package/dist/postgraphile/postgraphile-options-builder.js +0 -416
- package/dist/postgraphile/postgraphile-options-builder.js.map +0 -1
- package/dist/postgraphile/websocket-utils.d.ts +0 -11
- package/dist/postgraphile/websocket-utils.d.ts.map +0 -1
- package/dist/postgraphile/websocket-utils.js +0 -17
- package/dist/postgraphile/websocket-utils.js.map +0 -1
- package/src/common/errors/graphql-errors-handler.spec.ts +0 -1311
- package/src/common/errors/graphql-errors-handler.ts +0 -194
- package/src/plugins/add-error-codes-enum-plugin.ts +0 -101
- package/src/plugins/annotate-types-with-permissions-plugin.spec.ts +0 -158
- package/src/plugins/annotate-types-with-permissions-plugin.ts +0 -205
- package/src/plugins/deprecate-stray-node-id-fields-plugin.ts +0 -41
- package/src/plugins/generic-bulk-plugin-factory.ts +0 -313
- package/src/plugins/graphiql-dark-mode-plugin-hook.ts +0 -224
- package/src/plugins/graphiql-management-mode-plugin-hook.ts +0 -46
- package/src/plugins/index.ts +0 -10
- package/src/plugins/omit-from-query-root-plugin.ts +0 -69
- package/src/plugins/operations-enum-generator-plugin-factory.ts +0 -130
- package/src/plugins/subscriptions-plugin-factory.ts +0 -114
- package/src/plugins/validation-directives-plugin.ts +0 -141
- package/src/postgraphile/index.ts +0 -2
- package/src/postgraphile/postgraphile-options-builder.spec.ts +0 -744
- package/src/postgraphile/postgraphile-options-builder.ts +0 -518
- package/src/postgraphile/websocket-utils.ts +0 -19
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-pg-error-mapper.d.ts","sourceRoot":"","sources":["../../../src/common/errors/default-pg-error-mapper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"default-pg-error-mapper.d.ts","sourceRoot":"","sources":["../../../src/common/errors/default-pg-error-mapper.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgB,eAAe,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE3E;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,iBAAiB,CAAC,eAAe,CAsEnE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-pg-error-mapper.js","sourceRoot":"","sources":["../../../src/common/errors/default-pg-error-mapper.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"default-pg-error-mapper.js","sourceRoot":"","sources":["../../../src/common/errors/default-pg-error-mapper.ts"],"names":[],"mappings":";;;AAAA,2CAAsC;AACtC,wCAAgD;AAChD,mDAA+C;AAC/C,mDAA8C;AAG9C;;GAEG;AACI,MAAM,oBAAoB,GAAuC,CACtE,KAAY,EACZ,YAA8B,EACD,EAAE;;IAC/B,MAAM,aAAa,GAAG,CAAC,MAAC,KAAsB,aAAtB,KAAK,uBAAL,KAAK,CAAmB,aAAa,mCAC3D,KAAK,CAA8C,CAAC;IACtD,6GAA6G;IAC7G,2EAA2E;IAC3E,uEAAuE;IACvE,IAAI,CAAA,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,IAAI,0CAAE,MAAM,MAAK,CAAC,EAAE;QACrC,OAAO,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,yBAAyB,CAAC;QAC3C,KAAK,2BAAW,CAAC,8BAA8B,CAAC;QAChD,KAAK,2BAAW,CAAC,6BAA6B;YAC5C,OAAO;gBACL,OAAO,EAAE,aAAa,CAAC,OAAO;gBAC9B,IAAI,EAAE,4BAAY,CAAC,wBAAwB,CAAC,IAAI;aACjD,CAAC;QACJ,KAAK,2BAAW,CAAC,2BAA2B,CAAC,CAAC;YAC5C,OAAO;gBACL,OAAO,EAAE,aAAa,CAAC,OAAO;gBAC9B,IAAI,EAAE,4BAAY,CAAC,8BAA8B,CAAC,IAAI;aACvD,CAAC;SACH;QACD,KAAK,2BAAW,CAAC,oBAAoB,CAAC,CAAC;YACrC,OAAO;gBACL,OAAO,EAAE,aAAa,CAAC,OAAO;gBAC9B,IAAI,EAAE,4BAAY,CAAC,sBAAsB,CAAC,IAAI;aAC/C,CAAC;SACH;QACD;YACE,OAAO,4BAAY,CAAC,sBAAsB,CAAC;KAC9C;AACH,CAAC,CAAC;AAtEW,QAAA,oBAAoB,wBAsE/B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Logger } from '../logging';
|
|
2
|
+
import { Dict } from '../types';
|
|
3
|
+
import { WriteLogMapper } from './default-write-log-mapper';
|
|
4
|
+
import { GraphQLError, GraphQLErrorExtended, MosaicErrorMapper } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* GraphQL based interface - contains data about a failed GraphQL request.
|
|
7
|
+
*/
|
|
8
|
+
interface GraphQlOperation {
|
|
9
|
+
/**
|
|
10
|
+
* Type of operation, e.g. query, mutation or subscription.
|
|
11
|
+
*/
|
|
12
|
+
operation?: 'query' | 'mutation' | 'subscription';
|
|
13
|
+
/**
|
|
14
|
+
* Name of operation, if defined.
|
|
15
|
+
*/
|
|
16
|
+
name?: string;
|
|
17
|
+
/**
|
|
18
|
+
* List of root endpoints, since a single operation can perform multiple queries/mutations.
|
|
19
|
+
*/
|
|
20
|
+
rootEndpoints?: string[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Customize the default GraphQL errors to nicer ones
|
|
24
|
+
* @param errorDataMapper A mosaic error mapper that maps known error types to user friendly ones.
|
|
25
|
+
* @returns A function that can be used in the GraphQL error handler for nice error messages
|
|
26
|
+
*/
|
|
27
|
+
export declare const customizeGraphQlErrorFields: (errorDataMapper?: MosaicErrorMapper) => (error: GraphQLError, originalError?: Error | null) => {
|
|
28
|
+
message?: string;
|
|
29
|
+
code?: string;
|
|
30
|
+
extensions?: Dict<unknown>;
|
|
31
|
+
};
|
|
32
|
+
export declare const logGraphQlError: (writeLogMapper?: WriteLogMapper, logger?: Logger) => (error: GraphQLErrorExtended, originalError?: Error | null, graphQlOperations?: GraphQlOperation[]) => void;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=graphql-errors-customization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-errors-customization.d.ts","sourceRoot":"","sources":["../../../src/common/errors/graphql-errors-customization.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGhF;;GAEG;AACH,UAAU,gBAAgB;IACxB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,cAAc,CAAC;IAClD;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AA6CD;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,qBACpB,iBAAiB,aAE5B,YAAY,kBACH,KAAK,GAAG,IAAI,KACzB;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC;CAqB5B,CAAC;AAEF,eAAO,MAAM,eAAe,oBACT,cAAc,WACvB,MAAM,aAGL,oBAAoB,kBACX,KAAK,GAAG,IAAI,sBACR,gBAAgB,EAAE,KACrC,IA4BJ,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.logGraphQlError = exports.customizeGraphQlErrorFields = void 0;
|
|
15
|
+
const helpers_1 = require("../helpers");
|
|
16
|
+
const logging_1 = require("../logging");
|
|
17
|
+
const mosaic_errors_1 = require("./mosaic-errors");
|
|
18
|
+
const getCode = (error, originalError) => {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const code = (originalError === null || originalError === void 0 ? void 0 : originalError.code) ||
|
|
21
|
+
((_b = (_a = error.extensions) === null || _a === void 0 ? void 0 : _a.exception) === null || _b === void 0 ? void 0 : _b.code);
|
|
22
|
+
if (!code || originalError instanceof TypeError) {
|
|
23
|
+
return mosaic_errors_1.MosaicErrors.GraphQLValidationFailed.code;
|
|
24
|
+
}
|
|
25
|
+
return code;
|
|
26
|
+
};
|
|
27
|
+
const getExtensions = (error) => {
|
|
28
|
+
const originalError = error.originalError;
|
|
29
|
+
if (!(originalError === null || originalError === void 0 ? void 0 : originalError.details)) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
33
|
+
const _a = originalError.details, { skipMaskTag } = _a, details = __rest(_a, ["skipMaskTag"]);
|
|
34
|
+
return (0, helpers_1.isEmptyObject)(details) ? undefined : details;
|
|
35
|
+
};
|
|
36
|
+
const getMessage = (messageOrObject) => {
|
|
37
|
+
const defaultMessage = 'An error without a message has occurred.';
|
|
38
|
+
if ((0, helpers_1.isNullOrWhitespace)(messageOrObject)) {
|
|
39
|
+
return defaultMessage;
|
|
40
|
+
}
|
|
41
|
+
if (typeof messageOrObject === 'string') {
|
|
42
|
+
return messageOrObject;
|
|
43
|
+
}
|
|
44
|
+
if (typeof messageOrObject === 'object' && messageOrObject.message) {
|
|
45
|
+
return getMessage(messageOrObject.message);
|
|
46
|
+
}
|
|
47
|
+
return defaultMessage;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Customize the default GraphQL errors to nicer ones
|
|
51
|
+
* @param errorDataMapper A mosaic error mapper that maps known error types to user friendly ones.
|
|
52
|
+
* @returns A function that can be used in the GraphQL error handler for nice error messages
|
|
53
|
+
*/
|
|
54
|
+
const customizeGraphQlErrorFields = (errorDataMapper) => {
|
|
55
|
+
return (error, originalError) => {
|
|
56
|
+
const defaultMessage = getMessage(error.message);
|
|
57
|
+
const defaultCode = getCode(error, originalError);
|
|
58
|
+
const defaultExtensions = getExtensions(error);
|
|
59
|
+
const override = errorDataMapper === null || errorDataMapper === void 0 ? void 0 : errorDataMapper(originalError !== null && originalError !== void 0 ? originalError : error);
|
|
60
|
+
return {
|
|
61
|
+
message: (override === null || override === void 0 ? void 0 : override.message) || defaultMessage,
|
|
62
|
+
code: (override === null || override === void 0 ? void 0 : override.code) || defaultCode || mosaic_errors_1.MosaicErrors.UnhandledError.code,
|
|
63
|
+
extensions: (override === null || override === void 0 ? void 0 : override.details) || defaultExtensions,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
exports.customizeGraphQlErrorFields = customizeGraphQlErrorFields;
|
|
68
|
+
const logGraphQlError = (writeLogMapper, logger = new logging_1.Logger({ context: 'GraphQLErrorHandler' })) => {
|
|
69
|
+
return (error, originalError, graphQlOperations) => {
|
|
70
|
+
const { message } = error, _a = error.extensions, { timestamp: logtime, exception: { code } } = _a, rest = __rest(_a, ["timestamp", "exception"]);
|
|
71
|
+
const log = {
|
|
72
|
+
logtime,
|
|
73
|
+
message,
|
|
74
|
+
details: (0, helpers_1.removeEmptyProperties)(Object.assign(Object.assign({}, rest), { code,
|
|
75
|
+
graphQlOperations })),
|
|
76
|
+
};
|
|
77
|
+
writeLogMapper
|
|
78
|
+
? writeLogMapper(log, originalError !== null && originalError !== void 0 ? originalError : error, logger)
|
|
79
|
+
: logger.log(originalError !== null && originalError !== void 0 ? originalError : error, log);
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
exports.logGraphQlError = logGraphQlError;
|
|
83
|
+
//# sourceMappingURL=graphql-errors-customization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-errors-customization.js","sourceRoot":"","sources":["../../../src/common/errors/graphql-errors-customization.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,wCAIoB;AACpB,wCAAoC;AAGpC,mDAA+C;AAsB/C,MAAM,OAAO,GAAG,CAAC,KAAmB,EAAE,aAA4B,EAAU,EAAE;;IAC5E,MAAM,IAAI,GACR,CAAC,aAA0C,aAA1C,aAAa,uBAAb,aAAa,CAA+B,IAAI;SACjD,MAAA,MAAA,KAAK,CAAC,UAAU,0CAAE,SAAS,0CAAE,IAAI,CAAA,CAAC;IACpC,IAAI,CAAC,IAAI,IAAI,aAAa,YAAY,SAAS,EAAE;QAC/C,OAAO,4BAAY,CAAC,uBAAuB,CAAC,IAAI,CAAC;KAClD;IACD,OAAO,IAAI,CAAC;AACd,CAAC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export * from './assert-error';
|
|
|
2
2
|
export * from './default-pg-error-mapper';
|
|
3
3
|
export * from './default-write-log-mapper';
|
|
4
4
|
export * from './deprecated';
|
|
5
|
-
export * from './graphql-errors-
|
|
5
|
+
export * from './graphql-errors-customization';
|
|
6
6
|
export * from './handle-global-errors';
|
|
7
7
|
export * from './mosaic-error-mapping-factory';
|
|
8
8
|
export * from './mosaic-errors';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,cAAc,CAAC;AAC7B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,cAAc,CAAC;AAC7B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC"}
|
|
@@ -18,7 +18,7 @@ __exportStar(require("./assert-error"), exports);
|
|
|
18
18
|
__exportStar(require("./default-pg-error-mapper"), exports);
|
|
19
19
|
__exportStar(require("./default-write-log-mapper"), exports);
|
|
20
20
|
__exportStar(require("./deprecated"), exports);
|
|
21
|
-
__exportStar(require("./graphql-errors-
|
|
21
|
+
__exportStar(require("./graphql-errors-customization"), exports);
|
|
22
22
|
__exportStar(require("./handle-global-errors"), exports);
|
|
23
23
|
__exportStar(require("./mosaic-error-mapping-factory"), exports);
|
|
24
24
|
__exportStar(require("./mosaic-errors"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/errors/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,4DAA0C;AAC1C,6DAA2C;AAC3C,+CAA6B;AAC7B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/errors/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,4DAA0C;AAC1C,6DAA2C;AAC3C,+CAA6B;AAC7B,iEAA+C;AAC/C,yDAAuC;AACvC,iEAA+C;AAC/C,kDAAgC;AAChC,kDAAgC;AAChC,oDAAkC;AAClC,0CAAwB"}
|
|
@@ -1,5 +1,88 @@
|
|
|
1
|
-
import { GraphQLErrorExtended } from 'postgraphile';
|
|
2
1
|
import { Dict } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* GraphQL based interface for an error.
|
|
4
|
+
* @source GraphQL npm library
|
|
5
|
+
*/
|
|
6
|
+
export interface GraphQLError extends Error {
|
|
7
|
+
/**
|
|
8
|
+
* A message describing the Error for debugging purposes.
|
|
9
|
+
*
|
|
10
|
+
* Enumerable, and appears in the result of JSON.stringify().
|
|
11
|
+
*
|
|
12
|
+
* Note: should be treated as readonly, despite invariant usage.
|
|
13
|
+
*/
|
|
14
|
+
message: string;
|
|
15
|
+
/**
|
|
16
|
+
* An array of { line, column } locations within the source GraphQL document
|
|
17
|
+
* which correspond to this error.
|
|
18
|
+
*
|
|
19
|
+
* Errors during validation often contain multiple locations, for example to
|
|
20
|
+
* point out two things with the same name. Errors during execution include a
|
|
21
|
+
* single location, the field which produced the error.
|
|
22
|
+
*
|
|
23
|
+
* Enumerable, and appears in the result of JSON.stringify().
|
|
24
|
+
*/
|
|
25
|
+
readonly locations: readonly {
|
|
26
|
+
readonly line: number;
|
|
27
|
+
readonly column: number;
|
|
28
|
+
}[] | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* An array describing the JSON-path into the execution response which
|
|
31
|
+
* corresponds to this error. Only included for errors during execution.
|
|
32
|
+
*
|
|
33
|
+
* Enumerable, and appears in the result of JSON.stringify().
|
|
34
|
+
*/
|
|
35
|
+
readonly path: readonly (string | number)[] | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* An array of GraphQL AST Nodes corresponding to this error.
|
|
38
|
+
*/
|
|
39
|
+
readonly nodes: readonly unknown[] | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* The source GraphQL document corresponding to this error.
|
|
42
|
+
*
|
|
43
|
+
* Note that if this Error represents more than one node, the source may not
|
|
44
|
+
* represent nodes after the first node.
|
|
45
|
+
*/
|
|
46
|
+
readonly source: {
|
|
47
|
+
body: string;
|
|
48
|
+
name: string;
|
|
49
|
+
locationOffset: {
|
|
50
|
+
readonly line: number;
|
|
51
|
+
readonly column: number;
|
|
52
|
+
};
|
|
53
|
+
} | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* An array of character offsets within the source GraphQL document
|
|
56
|
+
* which correspond to this error.
|
|
57
|
+
*/
|
|
58
|
+
readonly positions: readonly number[] | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* The original error thrown from a field resolver during execution.
|
|
61
|
+
*/
|
|
62
|
+
readonly originalError: Error | undefined | null;
|
|
63
|
+
/**
|
|
64
|
+
* Extension fields to add to the formatted error.
|
|
65
|
+
*/
|
|
66
|
+
readonly extensions: {
|
|
67
|
+
[key: string]: any;
|
|
68
|
+
} | undefined;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* GraphQL error extended interface based on PostGraphile and the Mosaic library
|
|
72
|
+
*/
|
|
73
|
+
export interface GraphQLErrorExtended extends GraphQLError {
|
|
74
|
+
/** Extended Information for the (PostGraphile based) error */
|
|
75
|
+
extensions: {
|
|
76
|
+
/** The timestamp when the error was raised */
|
|
77
|
+
timestamp: string;
|
|
78
|
+
exception: {
|
|
79
|
+
hint?: string;
|
|
80
|
+
detail?: string;
|
|
81
|
+
code: string;
|
|
82
|
+
};
|
|
83
|
+
[key: string]: any;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
3
86
|
/**
|
|
4
87
|
* An error info object that represents a mapped Error to be thrown.
|
|
5
88
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../../src/common/errors/types/models.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../../src/common/errors/types/models.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,KAAK;IACzC;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;;;;OASG;IACH,QAAQ,CAAC,SAAS,EACd,SAAS;QACP,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACzB,EAAE,GACH,SAAS,CAAC;IAEd;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,SAAS,CAAC;IAExD;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,GAAG,SAAS,CAAC;IAE/C;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EACX;QACE,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,cAAc,EAAE;YACd,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;YACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;SACzB,CAAC;KACH,GACD,SAAS,CAAC;IAEd;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IAElD;;OAEG;IACH,QAAQ,CAAC,aAAa,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,CAAC;IA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MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;CACrC,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -16,8 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./common"), exports);
|
|
18
18
|
__exportStar(require("./middleware"), exports);
|
|
19
|
-
__exportStar(require("./plugins"), exports);
|
|
20
|
-
__exportStar(require("./postgraphile"), exports);
|
|
21
19
|
__exportStar(require("./publishing"), exports);
|
|
22
20
|
__exportStar(require("./seed-data"), exports);
|
|
23
21
|
__exportStar(require("./webhooks"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,+CAA6B;AAC7B
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,+CAA6B;AAC7B,+CAA6B;AAC7B,8CAA4B;AAC5B,6CAA2B"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Application, Request, Response } from 'express';
|
|
3
|
-
import { Server } from 'http';
|
|
4
|
-
import { Middleware } from 'postgraphile';
|
|
3
|
+
import { IncomingMessage, Server, ServerResponse } from 'http';
|
|
5
4
|
import { Logger } from '../common';
|
|
5
|
+
export declare type Middleware<Request extends IncomingMessage = IncomingMessage, Response extends ServerResponse = ServerResponse> = (req: Request, res: Response, next: (errOrEscape?: any) => void) => void;
|
|
6
6
|
/**
|
|
7
7
|
* Returns previously instantiated http server.
|
|
8
8
|
* @param app express app
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-server-with-websockets-middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/http-server-with-websockets-middleware.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,
|
|
1
|
+
{"version":3,"file":"http-server-with-websockets-middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/http-server-with-websockets-middleware.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,EAAgB,MAAM,MAAM,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAKnC,MAAM,CAAC,OAAO,MAAM,UAAU,CAC5B,OAAO,SAAS,eAAe,GAAG,eAAe,EACjD,QAAQ,SAAS,cAAc,GAAG,cAAc,IAC9C,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,WAAW,CAAC,EAAE,GAAG,KAAK,IAAI,KAAK,IAAI,CAAC;AAE7E;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAE7D;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,WAAW,GACf,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAEjC;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,GAAG,EAAE,WAAW,EAChB,MAAM,CAAC,EAAE,MAAM,EACf,oBAAoB,GAAE,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAO,GACzD,MAAM,CAkBR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-server-with-websockets-middleware.js","sourceRoot":"","sources":["../../src/middleware/http-server-with-websockets-middleware.ts"],"names":[],"mappings":";;;AACA,+
|
|
1
|
+
{"version":3,"file":"http-server-with-websockets-middleware.js","sourceRoot":"","sources":["../../src/middleware/http-server-with-websockets-middleware.ts"],"names":[],"mappings":";;;AACA,+BAA6E;AAG7E,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAC7C,MAAM,aAAa,GAAG,YAAY,CAAC;AAOnC;;;GAGG;AACH,SAAgB,aAAa,CAAC,GAAgB;IAC5C,OAAO,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;AAChC,CAAC;AAFD,sCAEC;AAED;;;GAGG;AACH,SAAgB,uBAAuB,CACrC,GAAgB;IAEhB,OAAO,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;AAChC,CAAC;AAJD,0DAIC;AAED;;;;;GAKG;AACH,SAAgB,6BAA6B,CAC3C,GAAgB,EAChB,MAAe,EACf,uBAAwD,EAAE;IAE1D,MAAM,UAAU,GAAG,IAAA,mBAAY,GAAE,CAAC;IAClC,IAAI,MAAM,EAAE;QACV,yHAAyH;QACzH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAY,EAAE,EAAE;YACtC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;KACJ;IAED,yEAAyE;IACzE,8DAA8D;IAC9D,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IAEnC,kEAAkE;IAClE,mCAAmC;IACnC,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,oBAAoB,CAAC,CAAC;IAE7C,OAAO,UAAU,CAAC;AACpB,CAAC;AAtBD,sEAsBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-service-common",
|
|
3
|
-
"version": "0.36.0
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"description": "Common helpers and PostgreSQL-related functionality",
|
|
5
5
|
"author": "Axinom",
|
|
6
6
|
"license": "PROPRIETARY",
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
"lint": "eslint . --ext .ts,.tsx,.js --color --cache"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@graphile/pg-pubsub": "^4.12.3",
|
|
34
33
|
"ajv": "^7.0.3",
|
|
35
34
|
"ajv-formats": "^2.1.1",
|
|
36
35
|
"endent": "^2.1.0",
|
|
@@ -38,16 +37,11 @@
|
|
|
38
37
|
"express": "^4.17.1",
|
|
39
38
|
"express-basic-auth": "^1.2.1",
|
|
40
39
|
"fast-stable-stringify": "^1.0.0",
|
|
41
|
-
"graphile-build": "^4.13.0",
|
|
42
|
-
"graphile-build-pg": "^4.13.0",
|
|
43
|
-
"graphile-utils": "^4.13.0",
|
|
44
|
-
"graphql": "^15.4.0",
|
|
45
40
|
"inflection": "^1.12.0",
|
|
46
41
|
"jest": "^29",
|
|
47
42
|
"jest-expect-message": "^1.1.3",
|
|
48
43
|
"moment": "^2.29.1",
|
|
49
44
|
"pg": "^8.5.1",
|
|
50
|
-
"postgraphile": "^4.13.0",
|
|
51
45
|
"prom-client": "^13.2.0",
|
|
52
46
|
"serialize-error": "^7.0.1",
|
|
53
47
|
"short-hash": "^1.0.0",
|
|
@@ -60,6 +54,7 @@
|
|
|
60
54
|
"@types/inflection": "^1.5.28",
|
|
61
55
|
"@types/jest": "^29",
|
|
62
56
|
"@types/jest-expect-message": "^1.1.0",
|
|
57
|
+
"@types/node": "^18.11.18",
|
|
63
58
|
"@types/uuid": "^8.0.0",
|
|
64
59
|
"@types/verror": "^1.10.6",
|
|
65
60
|
"eslint": "^8.35.0",
|
|
@@ -70,5 +65,5 @@
|
|
|
70
65
|
"publishConfig": {
|
|
71
66
|
"access": "public"
|
|
72
67
|
},
|
|
73
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "cb1823de8e408b481091bfe0b0107815e8b49880"
|
|
74
69
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { GraphQLError } from 'graphql';
|
|
2
1
|
import { camelize } from 'inflection';
|
|
3
2
|
import { isNullOrWhitespace } from '../helpers';
|
|
4
3
|
import { MosaicErrors } from './mosaic-errors';
|
|
5
4
|
import { PgErrorCode } from './pg-error-code';
|
|
6
|
-
import { MosaicErrorInfo, MosaicErrorMapper } from './types';
|
|
5
|
+
import { GraphQLError, MosaicErrorInfo, MosaicErrorMapper } from './types';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Maps Postgres error message and code to more user-friendly message and code.
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import 'jest-extended';
|
|
2
|
+
import {
|
|
3
|
+
createOffsetDate,
|
|
4
|
+
dateToBeInRange,
|
|
5
|
+
getFirstMockResult,
|
|
6
|
+
toBeIso8601Strict,
|
|
7
|
+
} from '../helpers';
|
|
8
|
+
import { Logger, createTestLogConfig } from '../logging';
|
|
9
|
+
import { defaultPgErrorMapper } from './default-pg-error-mapper';
|
|
10
|
+
import { defaultWriteLogMapper } from './default-write-log-mapper';
|
|
11
|
+
import {
|
|
12
|
+
customizeGraphQlErrorFields,
|
|
13
|
+
logGraphQlError,
|
|
14
|
+
} from './graphql-errors-customization';
|
|
15
|
+
import { MosaicErrors } from './mosaic-errors';
|
|
16
|
+
import { GraphQLError, GraphQLErrorExtended, MosaicErrorMapper } from './types';
|
|
17
|
+
|
|
18
|
+
const createGraphQLError = (
|
|
19
|
+
message: string,
|
|
20
|
+
merge?: Partial<GraphQLErrorExtended>,
|
|
21
|
+
): GraphQLErrorExtended => {
|
|
22
|
+
const e = new Error(message) as any;
|
|
23
|
+
Object.assign(e, {
|
|
24
|
+
extensions: {
|
|
25
|
+
timestamp: new Date().toISOString(),
|
|
26
|
+
exception: {
|
|
27
|
+
code: 'GENERAL_GRAPHQL_ERROR',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
//TODO: remove backwards compatibility after 01-11-2023
|
|
31
|
+
timestamp: new Date().toISOString(),
|
|
32
|
+
code: 'GENERAL_GRAPHQL_ERROR',
|
|
33
|
+
details: undefined,
|
|
34
|
+
...merge,
|
|
35
|
+
});
|
|
36
|
+
return e as GraphQLErrorExtended;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
describe('GraphQL errors customization', () => {
|
|
40
|
+
let testLogger: Logger;
|
|
41
|
+
let timestampBeforeTest: Date;
|
|
42
|
+
let errorOverride: jest.SpyInstance;
|
|
43
|
+
let debugOverride: jest.SpyInstance;
|
|
44
|
+
|
|
45
|
+
const defaultCustomizer = customizeGraphQlErrorFields(defaultPgErrorMapper);
|
|
46
|
+
|
|
47
|
+
beforeAll(async () => {
|
|
48
|
+
const config = createTestLogConfig();
|
|
49
|
+
testLogger = new Logger({ config, context: 'GraphQLErrorHandler' });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
beforeEach(async () => {
|
|
53
|
+
timestampBeforeTest = createOffsetDate(-20);
|
|
54
|
+
errorOverride = jest
|
|
55
|
+
.spyOn(console, 'error')
|
|
56
|
+
.mockImplementation((obj) => JSON.parse(obj));
|
|
57
|
+
debugOverride = jest
|
|
58
|
+
.spyOn(console, 'debug')
|
|
59
|
+
.mockImplementation((obj) => JSON.parse(obj));
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
afterEach(async () => {
|
|
63
|
+
jest.restoreAllMocks();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should return default values when no errorDataMapper is provided', () => {
|
|
67
|
+
const error: GraphQLError = createGraphQLError('Sample error message');
|
|
68
|
+
|
|
69
|
+
const result = defaultCustomizer(error);
|
|
70
|
+
|
|
71
|
+
expect(result.message).toBe('Sample error message');
|
|
72
|
+
expect(result.code).toBe('GENERAL_GRAPHQL_ERROR');
|
|
73
|
+
expect(result.extensions).toBeUndefined();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should use errorDataMapper when provided', () => {
|
|
77
|
+
const error: GraphQLError = createGraphQLError('Sample error message');
|
|
78
|
+
const errorDataMapper: MosaicErrorMapper = () => ({
|
|
79
|
+
message: 'Custom error message',
|
|
80
|
+
code: 'CUSTOM_ERROR',
|
|
81
|
+
details: { custom: 'data' },
|
|
82
|
+
});
|
|
83
|
+
const customizer = customizeGraphQlErrorFields(errorDataMapper);
|
|
84
|
+
|
|
85
|
+
const result = customizer(error);
|
|
86
|
+
|
|
87
|
+
expect(result.message).toBe('Custom error message');
|
|
88
|
+
expect(result.code).toBe('CUSTOM_ERROR');
|
|
89
|
+
expect(result.extensions).toEqual({ custom: 'data' });
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should log error with default logger and context', () => {
|
|
93
|
+
const mockLogger = {
|
|
94
|
+
log: jest.fn(),
|
|
95
|
+
};
|
|
96
|
+
const error = createGraphQLError('Sample error message', {
|
|
97
|
+
extensions: {
|
|
98
|
+
timestamp: '2023-07-20T12:00:00',
|
|
99
|
+
exception: { code: 'ERROR_CODE' },
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const logFunction = logGraphQlError(undefined, mockLogger as any);
|
|
104
|
+
logFunction(error);
|
|
105
|
+
|
|
106
|
+
expect(mockLogger.log).toHaveBeenCalledTimes(1);
|
|
107
|
+
expect(mockLogger.log).toHaveBeenCalledWith(
|
|
108
|
+
error.originalError ?? error,
|
|
109
|
+
expect.objectContaining({
|
|
110
|
+
logtime: '2023-07-20T12:00:00',
|
|
111
|
+
message: 'Sample error message',
|
|
112
|
+
details: {
|
|
113
|
+
code: 'ERROR_CODE',
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('should log error with provided writeLogMapper', () => {
|
|
120
|
+
const mockLogger = {
|
|
121
|
+
log: jest.fn(),
|
|
122
|
+
};
|
|
123
|
+
const mockWriteLogMapper = jest.fn();
|
|
124
|
+
const originalError = new Error('original');
|
|
125
|
+
const error = createGraphQLError('Sample error message', {
|
|
126
|
+
extensions: {
|
|
127
|
+
timestamp: '2023-07-20T12:00:00',
|
|
128
|
+
exception: { code: 'ERROR_CODE' },
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const logFunction = logGraphQlError(mockWriteLogMapper, mockLogger as any);
|
|
133
|
+
logFunction(error, originalError);
|
|
134
|
+
|
|
135
|
+
expect(mockWriteLogMapper).toHaveBeenCalledTimes(1);
|
|
136
|
+
expect(mockWriteLogMapper).toHaveBeenCalledWith(
|
|
137
|
+
expect.objectContaining({
|
|
138
|
+
logtime: '2023-07-20T12:00:00',
|
|
139
|
+
message: 'Sample error message',
|
|
140
|
+
details: {
|
|
141
|
+
code: 'ERROR_CODE',
|
|
142
|
+
},
|
|
143
|
+
}),
|
|
144
|
+
originalError,
|
|
145
|
+
expect.anything(),
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('minimal graphql error without originalError -> valid response', async () => {
|
|
150
|
+
// Arrange
|
|
151
|
+
const now = new Date().toISOString();
|
|
152
|
+
const error = createGraphQLError('test', {
|
|
153
|
+
extensions: {
|
|
154
|
+
timestamp: now,
|
|
155
|
+
exception: { code: MosaicErrors.GraphQLValidationFailed.code },
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Act
|
|
160
|
+
const logger = logGraphQlError(defaultWriteLogMapper, testLogger);
|
|
161
|
+
logger(error);
|
|
162
|
+
|
|
163
|
+
// Assert
|
|
164
|
+
const loggedObject = getFirstMockResult<any>(debugOverride);
|
|
165
|
+
toBeIso8601Strict(loggedObject.logtime);
|
|
166
|
+
dateToBeInRange(loggedObject.logtime, timestampBeforeTest);
|
|
167
|
+
expect(loggedObject.error?.stack).toStartWith('Error: test\n');
|
|
168
|
+
expect(loggedObject).toMatchObject({
|
|
169
|
+
loglevel: 'DEBUG',
|
|
170
|
+
message: 'test',
|
|
171
|
+
context: 'GraphQLErrorHandler',
|
|
172
|
+
component: 'navy-asset-service_test',
|
|
173
|
+
details: {
|
|
174
|
+
code: MosaicErrors.GraphQLValidationFailed.code,
|
|
175
|
+
},
|
|
176
|
+
error: {
|
|
177
|
+
name: 'Error',
|
|
178
|
+
message: 'test',
|
|
179
|
+
stack: loggedObject.error?.stack,
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('minimal internal server error with originalError -> valid response', async () => {
|
|
185
|
+
// Arrange
|
|
186
|
+
const now = new Date().toISOString();
|
|
187
|
+
const originalError = new Error('original');
|
|
188
|
+
const error = createGraphQLError('test', {
|
|
189
|
+
extensions: {
|
|
190
|
+
timestamp: now,
|
|
191
|
+
exception: { code: MosaicErrors.InternalServerError.code },
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Act
|
|
196
|
+
const logger = logGraphQlError(defaultWriteLogMapper, testLogger);
|
|
197
|
+
logger(error, originalError);
|
|
198
|
+
|
|
199
|
+
// Assert
|
|
200
|
+
const loggedObject = getFirstMockResult<any>(errorOverride);
|
|
201
|
+
toBeIso8601Strict(loggedObject.logtime);
|
|
202
|
+
dateToBeInRange(loggedObject.logtime, timestampBeforeTest);
|
|
203
|
+
expect(loggedObject.error?.stack).toStartWith('Error: original\n');
|
|
204
|
+
expect(loggedObject).toMatchObject({
|
|
205
|
+
loglevel: 'ERROR',
|
|
206
|
+
message: 'test',
|
|
207
|
+
context: 'GraphQLErrorHandler',
|
|
208
|
+
component: 'navy-asset-service_test',
|
|
209
|
+
details: {
|
|
210
|
+
code: MosaicErrors.InternalServerError.code,
|
|
211
|
+
},
|
|
212
|
+
error: {
|
|
213
|
+
name: 'Error',
|
|
214
|
+
message: 'original',
|
|
215
|
+
stack: loggedObject.error?.stack,
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
});
|