websockets-topgg
Version:
A real-time WebSocket client for Top.gg that converts webhooks into a persistent connection, enabling seamless vote tracking, reminders, and enhanced community engagement.
30 lines • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiError = exports.CustomErrorCodes = void 0;
exports.throwApiError = throwApiError;
var CustomErrorCodes;
(function (CustomErrorCodes) {
CustomErrorCodes[CustomErrorCodes["GENERAL_ERROR"] = 0] = "GENERAL_ERROR";
CustomErrorCodes[CustomErrorCodes["MALFORMED_REQUEST"] = 1] = "MALFORMED_REQUEST";
CustomErrorCodes[CustomErrorCodes["INVALID_TOKEN"] = 2] = "INVALID_TOKEN";
CustomErrorCodes[CustomErrorCodes["NO_TOKEN_PROVIDED"] = 3] = "NO_TOKEN_PROVIDED";
CustomErrorCodes[CustomErrorCodes["UNKNOWN_USER"] = 10001] = "UNKNOWN_USER";
CustomErrorCodes[CustomErrorCodes["UNKNOWN_ENTITY"] = 10002] = "UNKNOWN_ENTITY";
CustomErrorCodes[CustomErrorCodes["UNKNOWN_USER_OR_ENTITY"] = 10003] = "UNKNOWN_USER_OR_ENTITY";
})(CustomErrorCodes || (exports.CustomErrorCodes = CustomErrorCodes = {}));
class ApiError extends Error {
constructor(message, code) {
super(message);
this.code = code;
this.name = "ApiError";
}
}
exports.ApiError = ApiError;
async function throwApiError(res) {
const body = (await res.json());
if (body.reason && body.code)
throw new ApiError(body.reason, body.code);
else
throw new ApiError(`Unknown API error: ${body.code || "no code provided"}: ${body.reason || "no reason provided"}`, CustomErrorCodes.GENERAL_ERROR);
}
//# sourceMappingURL=ApiError.js.map