apollo-server-errors
Advanced tools
Comparing version
@@ -21,2 +21,3 @@ "use strict"; | ||
function enrichError(error, debug = false) { | ||
var _a, _b, _c; | ||
const expanded = Object.create(Object.getPrototypeOf(error), { | ||
@@ -54,5 +55,5 @@ name: { | ||
...error.extensions, | ||
code: (error.extensions && error.extensions.code) || 'INTERNAL_SERVER_ERROR', | ||
code: ((_a = error.extensions) === null || _a === void 0 ? void 0 : _a.code) || 'INTERNAL_SERVER_ERROR', | ||
exception: { | ||
...(error.extensions && error.extensions.exception), | ||
...(_b = error.extensions) === null || _b === void 0 ? void 0 : _b.exception, | ||
...error.originalError, | ||
@@ -63,7 +64,4 @@ }, | ||
if (debug && !expanded.extensions.exception.stacktrace) { | ||
expanded.extensions.exception.stacktrace = | ||
(error.originalError && | ||
error.originalError.stack && | ||
error.originalError.stack.split('\n')) || | ||
(error.stack && error.stack.split('\n')); | ||
const stack = ((_c = error.originalError) === null || _c === void 0 ? void 0 : _c.stack) || error.stack; | ||
expanded.extensions.exception.stacktrace = stack === null || stack === void 0 ? void 0 : stack.split('\n'); | ||
} | ||
@@ -87,3 +85,3 @@ if (Object.keys(expanded.extensions.exception).length === 0) { | ||
function fromGraphQLError(error, options) { | ||
const copy = options && options.errorClass | ||
const copy = (options === null || options === void 0 ? void 0 : options.errorClass) | ||
? new options.errorClass(error.message) | ||
@@ -99,3 +97,3 @@ : new ApolloError(error.message); | ||
if (!copy.extensions.code) { | ||
copy.extensions.code = (options && options.code) || 'INTERNAL_SERVER_ERROR'; | ||
copy.extensions.code = (options === null || options === void 0 ? void 0 : options.code) || 'INTERNAL_SERVER_ERROR'; | ||
} | ||
@@ -102,0 +100,0 @@ Object.defineProperty(copy, 'originalError', { value: {} }); |
{ | ||
"name": "apollo-server-errors", | ||
"version": "3.0.1", | ||
"version": "3.1.0-alpha.0", | ||
"author": "Apollo <opensource@apollographql.com>", | ||
@@ -23,3 +23,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "856f7fbc151ebef4d6ca8a9efe801ecca3d4f9c3" | ||
"gitHead": "211cd84ce3d2c9be90248e6a69c8c26bf8d1cc17" | ||
} |
@@ -81,6 +81,5 @@ import { | ||
...error.extensions, | ||
code: | ||
(error.extensions && error.extensions.code) || 'INTERNAL_SERVER_ERROR', | ||
code: error.extensions?.code || 'INTERNAL_SERVER_ERROR', | ||
exception: { | ||
...(error.extensions && error.extensions.exception), | ||
...error.extensions?.exception, | ||
...(error.originalError as any), | ||
@@ -95,7 +94,4 @@ }, | ||
if (debug && !expanded.extensions.exception.stacktrace) { | ||
expanded.extensions.exception.stacktrace = | ||
(error.originalError && | ||
error.originalError.stack && | ||
error.originalError.stack.split('\n')) || | ||
(error.stack && error.stack.split('\n')); | ||
const stack = error.originalError?.stack || error.stack; | ||
expanded.extensions.exception.stacktrace = stack?.split('\n'); | ||
} | ||
@@ -132,6 +128,5 @@ | ||
export function fromGraphQLError(error: GraphQLError, options?: ErrorOptions) { | ||
const copy: ApolloError = | ||
options && options.errorClass | ||
? new options.errorClass(error.message) | ||
: new ApolloError(error.message); | ||
const copy: ApolloError = options?.errorClass | ||
? new options.errorClass(error.message) | ||
: new ApolloError(error.message); | ||
@@ -151,3 +146,3 @@ // copy enumerable keys | ||
if (!copy.extensions.code) { | ||
copy.extensions.code = (options && options.code) || 'INTERNAL_SERVER_ERROR'; | ||
copy.extensions.code = options?.code || 'INTERNAL_SERVER_ERROR'; | ||
} | ||
@@ -154,0 +149,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
60548
-0.16%560
-1.23%1
Infinity%