@@ -10,4 +10,7 @@ export declare class YqgStatus { | ||
| } | ||
| export declare class YqgError extends Error { | ||
| yqgStatus: YqgStatus; | ||
| } | ||
| export interface YqgStatusCodeMap { | ||
| [index: string]: string; | ||
| } |
+18
-0
| "use strict"; | ||
| var __extends = (this && this.__extends) || (function () { | ||
| var extendStatics = Object.setPrototypeOf || | ||
| ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
| 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 }); | ||
@@ -15,1 +25,9 @@ var YqgStatus = (function () { | ||
| exports.YqgResponse = YqgResponse; | ||
| var YqgError = (function (_super) { | ||
| __extends(YqgError, _super); | ||
| function YqgError() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return YqgError; | ||
| }(Error)); | ||
| exports.YqgError = YqgError; |
@@ -13,4 +13,5 @@ import { YqgStatus, YqgResponse, YqgStatusCodeMap } from './constant'; | ||
| error(code: number | YqgStatus | Error, detail?: string): YqgResponse; | ||
| throw(code: number | YqgStatus | Error, detail?: string): never; | ||
| } | ||
| declare const _default: ResponseProtocol; | ||
| export default _default; |
@@ -57,4 +57,13 @@ "use strict"; | ||
| }; | ||
| ResponseProtocol.prototype.throw = function (code, detail) { | ||
| var status = this.status(code); | ||
| if (detail) { | ||
| status.detail = detail; | ||
| } | ||
| var yqgError = new constant_1.YqgError(status.detail); | ||
| yqgError.yqgStatus = status; | ||
| throw yqgError; | ||
| }; | ||
| return ResponseProtocol; | ||
| }()); | ||
| exports.default = new ResponseProtocol({ map: yqg_status_code_map_1.default }); |
+1
-1
| { | ||
| "name": "@yqg/http", | ||
| "version": "0.0.1", | ||
| "version": "0.0.2", | ||
| "author": "YQG <developer@yangqianguan.com>", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/yqg-fe/yqg-util/tree/master/packages/@yqg/http", |
7476
18.65%202
18.13%