UNPKG

kaven-utils

Version:

Utils for Node.js.

63 lines (62 loc) 1.66 kB
/******************************************************************** * @author: Kaven * @email: kaven@wuwenkai.com * @website: http://blog.kaven.xyz * @file: [Kaven-Utils] /src/KavenRequestResult.ts * @create: 2023-12-08 14:51:37.670 * @modify: 2024-11-01 10:48:07.332 * @version: 5.4.5 * @times: 2 * @lines: 79 * @copyright: Copyright © 2023-2024 Kaven. All Rights Reserved. * @description: [description] * @license: [license] ********************************************************************/ import { IsSuccessStatusCode } from "kaven-basic"; export class KavenRequestResult { chunkList; status; statusText; headers; text; json; constructor(chunkList, status, statusText, headers) { this.chunkList = chunkList; this.status = status; this.statusText = statusText; this.headers = headers; } get Status() { return this.status; } get StatusText() { return this.statusText; } get Headers() { return this.headers; } get IsSuccess() { return IsSuccessStatusCode(this.status); } get HasData() { return this.chunkList.length > 0; } get Text() { if (this.text !== undefined) { return this.text; } if (this.HasData) { this.text = this.chunkList.join(""); } return this.text; } get Json() { if (this.json) { return this.json; } if (this.Text) { this.json = JSON.parse(this.Text); } return this.json; } }