aws-crt
Version:
NodeJS bindings to the aws-c-* libraries
63 lines • 2.1 kB
JavaScript
;
/*
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const binding_1 = __importDefault(require("./binding"));
const util_1 = require("util");
/**
* Represents an error encountered in native code. Can also be used to convert an error code(Number) into
* a human-readable string.
*/
class CrtError extends Error {
/** @var error - The original error. Most often an error_code, but possibly some other context */
constructor(error) {
super(extract_message(error));
this.error = error;
this.error_code = extract_code(error);
this.error_name = extract_name(error);
}
}
exports.CrtError = CrtError;
function extract_message(error) {
if (util_1.isNumber(error)) {
return binding_1.default.error_code_to_string(error);
}
else if (error instanceof CrtError) {
return error.message;
}
return error.toString();
}
function extract_code(error) {
if (util_1.isNumber(error)) {
return error;
}
else if (error instanceof CrtError) {
return error.error_code;
}
return undefined;
}
function extract_name(error) {
if (util_1.isNumber(error)) {
return binding_1.default.error_code_to_name(error);
}
else if (error instanceof CrtError) {
return error.error_name;
}
return undefined;
}
//# sourceMappingURL=error.js.map