kucoin-universal-sdk
Version:
Official KuCoin Universal SDK.
59 lines • 1.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WsMessage = exports.RestError = exports.RestResponse = void 0;
const class_transformer_1 = require("class-transformer");
/**
* RestResponse represents a generic response from the REST API.
*/
class RestResponse {
static fromJson(json) {
return (0, class_transformer_1.plainToInstance)(RestResponse, JSON.parse(json));
}
checkRestResponseError() {
/**
* Code for success
*/
const CodeSuccess = '200000';
if (this.code === CodeSuccess) {
return;
}
throw new RestError(this, new Error(`Server returned error, code: {${this.code}}, message: {${this.msg || 'unknown'}}`));
}
}
exports.RestResponse = RestResponse;
class RestError extends Error {
constructor(response, err) {
super((err === null || err === void 0 ? void 0 : err.message) || 'unknown');
this.response = response;
this.err = err;
}
toString() {
var _a;
if (this.response) {
return `request error, server code: ${this.response.code}, server msg: ${this.response.msg}, context msg: ${((_a = this.err) === null || _a === void 0 ? void 0 : _a.message) || 'unknown'}`;
}
return `request error, ${this.err}`;
}
getError() {
return this.err;
}
getCommonResponse() {
return this.response;
}
}
exports.RestError = RestError;
/**
* WsMessage represents a message between the WebSocket client and server.
*/
class WsMessage {
constructor() {
this.id = '';
this.topic = '';
this.subject = '';
}
static fromJson(json) {
return (0, class_transformer_1.plainToInstance)(WsMessage, JSON.parse(json));
}
}
exports.WsMessage = WsMessage;
//# sourceMappingURL=common.js.map