@halsp/http
Version:
支持 Halsp HTTP 请求
35 lines • 1.07 kB
JavaScript
import { getReasonPhrase } from "http-status-codes";
import { initHeaderHandler } from "../context/header-handler.mjs";
import { HalspException, isString } from "@halsp/core";
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export class HttpException extends HalspException {
status;
constructor(status, error) {
super(error);
this.status = status;
if (!this.message) {
this.message = getReasonPhrase(status);
}
this.name = this.constructor.name;
initHeaderHandler(this, () => this.headers, () => this.headers);
}
#headers = {};
get headers() {
return this.#headers;
}
toPlainObject() {
const obj = {
status: this.status,
message: this.message,
};
if (this.error && !isString(this.error)) {
Object.assign(obj, this.error);
delete obj["inner"];
return obj;
}
else {
return obj;
}
}
}
//# sourceMappingURL=http-exception.js.map