standard-response
Version:
Typescript standard response type for rest requests
59 lines (58 loc) • 2.2 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.StandardResponse = exports.StandardResponseWithData = exports.Jsonizable = void 0;
var StandardError_1 = require("./StandardError");
var Jsonizable = /** @class */ (function () {
function Jsonizable() {
}
Jsonizable.prototype.toJson = function () {
return JSON.stringify(this);
};
return Jsonizable;
}());
exports.Jsonizable = Jsonizable;
/**
* Standard response with data of type T
*/
var StandardResponseWithData = /** @class */ (function (_super) {
__extends(StandardResponseWithData, _super);
function StandardResponseWithData(data) {
var _this = _super.call(this) || this;
_this.errorMessage = "";
_this.data = null;
_this.error = new StandardError_1.StandardError();
_this.data = {};
Object.assign(_this, data);
return _this;
}
return StandardResponseWithData;
}(Jsonizable));
exports.StandardResponseWithData = StandardResponseWithData;
/**
* Standard response with data of type any
*/
var StandardResponse = /** @class */ (function (_super) {
__extends(StandardResponse, _super);
function StandardResponse() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.errorMessage = "";
_this.data = null;
_this.error = new StandardError_1.StandardError();
return _this;
}
return StandardResponse;
}(Jsonizable));
exports.StandardResponse = StandardResponse;