kuzzle-sdk
Version:
Official Javascript SDK for Kuzzle
76 lines • 2.99 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KuzzleError = void 0;
const stackTrace_1 = require("./utils/stackTrace");
/**
* Standard Kuzzle error.
*
* @see https://docs.kuzzle.io/core/2/api/errors/types/
*/
class KuzzleError extends Error {
/**
* This class represents a Kuzzle API error.
* The SDK stack is needed alongside the protocol used.
* Those information will allow to construct a enhanced stacktrace:
*
* BadRequestError: Trololol
at new BadRequestError (/home/aschen/projets/kuzzleio/kuzzle/lib/kerror/errors/badRequestError.ts:26:5)
> at BaseController.handler [as sayHello] (/home/aschen/projets/kuzzleio/kuzzle/test.js:9:15)
at doAction (/home/aschen/projets/kuzzleio/kuzzle/lib/api/funnel.js:759:47)
at Funnel.processRequest (/home/aschen/projets/kuzzleio/kuzzle/lib/api/funnel.js:423:34)
|
|
HttpProtocol
|
|
at HttpProtocol.query (/home/aschen/projets/kuzzleio/sdk-javascript/src/protocols/abstract/Base.ts:127:19)
at Proxy.query (/home/aschen/projets/kuzzleio/sdk-javascript/src/Kuzzle.ts:598:26)
> at /home/aschen/projets/kuzzleio/sdk-javascript/test.js:8:18
at processTicksAndRejections (internal/process/task_queues.js:97:5)
*/
constructor(apiError, sdkStack, protocol, request) {
super(apiError.message);
this.status = apiError.status;
this.id = apiError.id;
this.code = apiError.code;
this.props = apiError.props;
if (request) {
this.controller = request.controller;
this.collection = request.collection;
this.action = request.action;
this.index = request.index;
this.volatile = request.volatile;
this.requestId = request.requestId;
this._id = request._id;
}
// PartialError
if (apiError.errors) {
this.errors = apiError.errors;
this.count = apiError.count;
}
// If we have a stacktrace coming from Kuzzle, merge it with
// the SDK one
if (apiError.stack) {
this.kuzzleStack = apiError.stack;
this.stack = apiError.stack + "\n";
this.stack += " |\n";
this.stack += " |\n";
this.stack += ` ${protocol}\n`;
this.stack += " |\n";
this.stack += " |\n";
}
else {
this.stack = `KuzzleError: ${apiError.message}\n`;
}
// Append the SDK stacktrace
if (sdkStack) {
this.stack += sdkStack
.split("\n")
.map(stackTrace_1.hilightUserCode)
.slice(1)
.join("\n");
}
}
}
exports.KuzzleError = KuzzleError;
//# sourceMappingURL=KuzzleError.js.map