/
response.ts
47 lines (38 loc) · 960 Bytes
/
response.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2024 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
/**
* @module request
*/
import type { IRequest, IResponse } from 'jodit/types';
export class Response<T> implements IResponse<T> {
readonly status: number;
readonly statusText: string;
readonly request: IRequest;
get url(): string {
return this.request.url;
}
private readonly body: string | Blob;
constructor(
request: IRequest,
status: number,
statusText: string,
body: string | Blob
) {
this.request = request;
this.status = status;
this.statusText = statusText;
this.body = body;
}
async json(): Promise<T> {
return JSON.parse(this.body as string);
}
text(): Promise<string> {
return Promise.resolve(this.body as string);
}
async blob(): Promise<Blob> {
return this.body as Blob;
}
}