@litert/televoke
Version:
A simple RPC service framework.
78 lines • 2.74 kB
JavaScript
;
/**
* Copyright 2025 Angus.Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.errors = exports.TvErrorResponse = exports.ProtocolError = exports.TelevokeError = void 0;
const Constants = require("./Constants");
/**
* The base class of all Televoke errors.
*/
class TelevokeError extends Error {
constructor(name, message, origin = null) {
super(message);
this.origin = origin;
this.name = name;
}
}
exports.TelevokeError = TelevokeError;
class ProtocolError extends TelevokeError {
constructor(message, data, origin) {
super(Constants.PROTOCOL_ERROR_NAMESPACE, message, origin);
this.data = data;
}
}
exports.ProtocolError = ProtocolError;
function defineProtocolError(name) {
return {
[name]: class extends ProtocolError {
constructor(data = null, origin = null) {
super(name, data, origin);
}
},
};
}
const errorCtors = {
...defineProtocolError('incomplete_packet'),
...defineProtocolError('invalid_packet'),
...defineProtocolError('invalid_response'),
...defineProtocolError('channel_inactive'),
...defineProtocolError('channel_closed'),
...defineProtocolError('api_not_found'),
...defineProtocolError('cmd_not_impl'),
...defineProtocolError('network_error'),
...defineProtocolError('stream_not_found'),
...defineProtocolError('stream_aborted'),
...defineProtocolError('stream_closed'),
...defineProtocolError('stream_index_mismatch'),
...defineProtocolError('system_busy'),
...defineProtocolError('server_internal_error'),
...defineProtocolError('timeout'),
...defineProtocolError('unknown'),
...defineProtocolError('unprocessable_error'),
['app_error']: class AppError extends TelevokeError {
constructor(message, origin = null) {
super(Constants.APP_ERROR_NAMESPACE, message, origin);
}
}
};
class TvErrorResponse {
constructor(data) {
this.data = data;
}
}
exports.TvErrorResponse = TvErrorResponse;
exports.errors = errorCtors;
//# sourceMappingURL=Errors.js.map