@slack/webhook
Version:
Official library for using the Slack Platform's Incoming Webhooks
41 lines • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.httpErrorWithOriginal = exports.requestErrorWithOriginal = exports.ErrorCode = void 0;
/**
* A dictionary of codes for errors produced by this package
*/
var ErrorCode;
(function (ErrorCode) {
ErrorCode["RequestError"] = "slack_webhook_request_error";
ErrorCode["HTTPError"] = "slack_webhook_http_error";
})(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
/**
* Factory for producing a {@link CodedError} from a generic error
*/
function errorWithCode(error, code) {
// NOTE: might be able to return something more specific than a CodedError with conditional typing
const codedError = error;
codedError.code = code;
return codedError;
}
/**
* A factory to create IncomingWebhookRequestError objects
* @param original The original error
*/
function requestErrorWithOriginal(original) {
const error = errorWithCode(new Error(`A request error occurred: ${original.message}`), ErrorCode.RequestError);
error.original = original;
return error;
}
exports.requestErrorWithOriginal = requestErrorWithOriginal;
/**
* A factory to create IncomingWebhookHTTPError objects
* @param original The original error
*/
function httpErrorWithOriginal(original) {
const error = errorWithCode(new Error(`An HTTP protocol error occurred: statusCode = ${original.response.status}`), ErrorCode.HTTPError);
error.original = original;
return error;
}
exports.httpErrorWithOriginal = httpErrorWithOriginal;
//# sourceMappingURL=errors.js.map