lin-cms-test
Version:
The core library of Lin CMS, this package is just for test!
248 lines (247 loc) • 7.31 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const assert_1 = tslib_1.__importDefault(require("assert"));
const lodash_1 = require("lodash");
class HttpException extends Error {
constructor(ex) {
super();
this.code = 500; // http 状态码
this.msg = "服务器未知错误"; // 返回的信息内容
this.errorCode = 999; // 特定的错误码
this.fields = ["msg", "errorCode"];
if (ex && ex.code) {
assert_1.default(lodash_1.isInteger(ex.code));
this.code = ex.code;
}
if (ex && ex.msg) {
this.msg = ex.msg;
}
if (ex && ex.errorCode) {
assert_1.default(lodash_1.isInteger(ex.errorCode));
this.errorCode = ex.errorCode;
}
}
}
exports.HttpException = HttpException;
class Success extends HttpException {
constructor(ex) {
super();
this.code = 201;
this.msg = "成功";
this.errorCode = 0;
if (ex && ex.code) {
assert_1.default(lodash_1.isInteger(ex.code));
this.code = ex.code;
}
if (ex && ex.msg) {
this.msg = ex.msg;
}
if (ex && ex.errorCode) {
assert_1.default(lodash_1.isInteger(ex.errorCode));
this.errorCode = ex.errorCode;
}
}
}
exports.Success = Success;
class Failed extends HttpException {
constructor(ex) {
super();
this.code = 400;
this.msg = "失败";
this.errorCode = 9999;
if (ex && ex.code) {
assert_1.default(lodash_1.isInteger(ex.code));
this.code = ex.code;
}
if (ex && ex.msg) {
this.msg = ex.msg;
}
if (ex && ex.errorCode) {
assert_1.default(lodash_1.isInteger(ex.errorCode));
this.errorCode = ex.errorCode;
}
}
}
exports.Failed = Failed;
class AuthFailed extends HttpException {
constructor(ex) {
super();
this.code = 401;
this.msg = "认证失败";
this.errorCode = 10000;
if (ex && ex.code) {
assert_1.default(lodash_1.isInteger(ex.code));
this.code = ex.code;
}
if (ex && ex.msg) {
this.msg = ex.msg;
}
if (ex && ex.errorCode) {
assert_1.default(lodash_1.isInteger(ex.errorCode));
this.errorCode = ex.errorCode;
}
}
}
exports.AuthFailed = AuthFailed;
class NotFound extends HttpException {
constructor(ex) {
super();
this.code = 404;
this.msg = "资源不存在";
this.errorCode = 10020;
if (ex && ex.code) {
assert_1.default(lodash_1.isInteger(ex.code));
this.code = ex.code;
}
if (ex && ex.msg) {
this.msg = ex.msg;
}
if (ex && ex.errorCode) {
assert_1.default(lodash_1.isInteger(ex.errorCode));
this.errorCode = ex.errorCode;
}
}
}
exports.NotFound = NotFound;
// msg必须每次指定,js没有默认的赋值操作,父类的构造函数在字段赋值之前。
class ParametersException extends HttpException {
constructor(ex) {
super();
this.code = 400;
this.msg = "参数错误";
this.errorCode = 10030;
if (ex && ex.code) {
assert_1.default(lodash_1.isInteger(ex.code));
this.code = ex.code;
}
if (ex && ex.msg) {
this.msg = ex.msg;
}
if (ex && ex.errorCode) {
assert_1.default(lodash_1.isInteger(ex.errorCode));
this.errorCode = ex.errorCode;
}
}
}
exports.ParametersException = ParametersException;
class InvalidTokenException extends HttpException {
constructor(ex) {
super();
this.code = 401;
this.msg = "令牌失效";
this.errorCode = 10040;
if (ex && ex.code) {
assert_1.default(lodash_1.isInteger(ex.code));
this.code = ex.code;
}
if (ex && ex.msg) {
this.msg = ex.msg;
}
if (ex && ex.errorCode) {
assert_1.default(lodash_1.isInteger(ex.errorCode));
this.errorCode = ex.errorCode;
}
}
}
exports.InvalidTokenException = InvalidTokenException;
class ExpiredTokenException extends HttpException {
constructor(ex) {
super();
this.code = 422;
this.msg = "令牌过期";
this.errorCode = 10050;
if (ex && ex.code) {
assert_1.default(lodash_1.isInteger(ex.code));
this.code = ex.code;
}
if (ex && ex.msg) {
this.msg = ex.msg;
}
if (ex && ex.errorCode) {
assert_1.default(lodash_1.isInteger(ex.errorCode));
this.errorCode = ex.errorCode;
}
}
}
exports.ExpiredTokenException = ExpiredTokenException;
class UnknownException extends HttpException {
constructor(ex) {
super();
this.code = 400;
this.msg = "服务器未知错误";
this.errorCode = 999;
if (ex && ex.code) {
assert_1.default(lodash_1.isInteger(ex.code));
this.code = ex.code;
}
if (ex && ex.msg) {
this.msg = ex.msg;
}
if (ex && ex.errorCode) {
assert_1.default(lodash_1.isInteger(ex.errorCode));
this.errorCode = ex.errorCode;
}
}
}
exports.UnknownException = UnknownException;
class RepeatException extends HttpException {
constructor(ex) {
super();
this.code = 400;
this.msg = "字段重复";
this.errorCode = 10060;
if (ex && ex.code) {
assert_1.default(lodash_1.isInteger(ex.code));
this.code = ex.code;
}
if (ex && ex.msg) {
this.msg = ex.msg;
}
if (ex && ex.errorCode) {
assert_1.default(lodash_1.isInteger(ex.errorCode));
this.errorCode = ex.errorCode;
}
}
}
exports.RepeatException = RepeatException;
class Forbidden extends HttpException {
constructor(ex) {
super();
this.code = 401;
this.msg = "不可操作";
this.errorCode = 10070;
if (ex && ex.code) {
assert_1.default(lodash_1.isInteger(ex.code));
this.code = ex.code;
}
if (ex && ex.msg) {
this.msg = ex.msg;
}
if (ex && ex.errorCode) {
assert_1.default(lodash_1.isInteger(ex.errorCode));
this.errorCode = ex.errorCode;
}
}
}
exports.Forbidden = Forbidden;
class MethodNotAllowed extends HttpException {
constructor(ex) {
super();
this.code = 405;
this.msg = "请求方法不允许";
this.errorCode = 10080;
if (ex && ex.code) {
assert_1.default(lodash_1.isInteger(ex.code));
this.code = ex.code;
}
if (ex && ex.msg) {
this.msg = ex.msg;
}
if (ex && ex.errorCode) {
assert_1.default(lodash_1.isInteger(ex.errorCode));
this.errorCode = ex.errorCode;
}
}
}
exports.MethodNotAllowed = MethodNotAllowed;