Files
SnowLuma/.pnpm-store/v11/files/82/ef1f3da8d5d73ab545d348b20a309076cec881f735a393f97eb5c965c8f78a23b54ab212c238563f9d80cb7b2abcdc5c0bac69a177712417c8b40f84521e4f
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

68 lines
2.0 KiB
Plaintext

Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
//#region src/client/fetch-result-please.ts
/**
* @description This file is a modified version of `fetch-result-please` (`ofetch`), minimalized and adapted to Hono's custom needs.
*
* @link https://www.npmjs.com/package/fetch-result-please
*/
const nullBodyResponses = /* @__PURE__ */ new Set([
101,
204,
205,
304
]);
/**
* Smartly parses and return the consumable result from a fetch `Response`.
*
* Throwing a structured error if the response is not `ok`. ({@link DetailedError})
*/
async function fetchRP(fetchRes) {
const _fetchRes = await fetchRes;
if ((_fetchRes.body || _fetchRes._bodyInit) && !nullBodyResponses.has(_fetchRes.status)) _fetchRes._data = await _fetchRes[detectResponseType(_fetchRes)]();
if (!_fetchRes.ok) throw new DetailedError(`${_fetchRes.status} ${_fetchRes.statusText}`, {
statusCode: _fetchRes?.status,
detail: {
data: _fetchRes?._data,
statusText: _fetchRes?.statusText
}
});
return _fetchRes._data;
}
var DetailedError = class extends Error {
/**
* Additional `message` that will be logged AND returned to client
*/
detail;
/**
* Additional `code` that will be logged AND returned to client
*/
code;
/**
* Additional value that will be logged AND NOT returned to client
*/
log;
/**
* Optionally set the status code to return, in a web server context
*/
statusCode;
constructor(message, options = {}) {
super(message);
this.name = "DetailedError";
this.log = options.log;
this.detail = options.detail;
this.code = options.code;
this.statusCode = options.statusCode;
}
};
const jsonRegex = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(?:;.+)?$/i;
function detectResponseType(response) {
const _contentType = response.headers.get("content-type");
if (!_contentType) return "text";
const contentType = _contentType.split(";").shift();
if (jsonRegex.test(contentType)) return "json";
return "text";
}
//#endregion
exports.DetailedError = DetailedError;
exports.fetchRP = fetchRP;