@basmilius/http-client 1.10.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/HttpAdapter.d.ts +6 -3
- package/dist/adapter/index.d.ts +1 -1
- package/dist/decorator/adapter.d.ts +2 -2
- package/dist/decorator/bound.d.ts +1 -1
- package/dist/decorator/debounce.d.ts +1 -1
- package/dist/decorator/dto/arrayProxy.d.ts +15 -15
- package/dist/decorator/dto/classProxy.d.ts +8 -8
- package/dist/decorator/dto/clone.d.ts +4 -4
- package/dist/decorator/dto/constant.d.ts +7 -7
- package/dist/decorator/dto/fill.d.ts +4 -4
- package/dist/decorator/dto/helper/areEqual.d.ts +4 -4
- package/dist/decorator/dto/helper/assertDto.d.ts +4 -4
- package/dist/decorator/dto/helper/circularProtect.d.ts +1 -1
- package/dist/decorator/dto/helper/cloneDto.d.ts +3 -3
- package/dist/decorator/dto/helper/executeIfDtoDirtyAndMarkClean.d.ts +7 -4
- package/dist/decorator/dto/helper/index.d.ts +17 -17
- package/dist/decorator/dto/helper/instance.d.ts +2 -2
- package/dist/decorator/dto/helper/isDto.d.ts +4 -4
- package/dist/decorator/dto/helper/isDtoClean.d.ts +3 -3
- package/dist/decorator/dto/helper/isDtoDirty.d.ts +3 -3
- package/dist/decorator/dto/helper/markDtoClean.d.ts +2 -2
- package/dist/decorator/dto/helper/markDtoDirty.d.ts +2 -2
- package/dist/decorator/dto/helper/relateDtoTo.d.ts +4 -4
- package/dist/decorator/dto/helper/relateValueTo.d.ts +4 -4
- package/dist/decorator/dto/helper/trackDto.d.ts +3 -3
- package/dist/decorator/dto/helper/triggerDto.d.ts +3 -3
- package/dist/decorator/dto/helper/unrelateDtoFrom.d.ts +4 -4
- package/dist/decorator/dto/helper/unrelateValueFrom.d.ts +4 -4
- package/dist/decorator/dto/index.d.ts +6 -6
- package/dist/decorator/dto/instanceProxy.d.ts +21 -21
- package/dist/decorator/dto/map.d.ts +2 -2
- package/dist/decorator/dto/refProxy.d.ts +30 -30
- package/dist/decorator/dto/serialize/deserialize.d.ts +1 -1
- package/dist/decorator/dto/serialize/deserializeArray.d.ts +1 -1
- package/dist/decorator/dto/serialize/deserializeDateTime.d.ts +3 -3
- package/dist/decorator/dto/serialize/deserializeDto.d.ts +3 -3
- package/dist/decorator/dto/serialize/deserializeObject.d.ts +1 -1
- package/dist/decorator/dto/serialize/deserializeUnknown.d.ts +1 -1
- package/dist/decorator/dto/serialize/index.d.ts +2 -2
- package/dist/decorator/dto/serialize/isSerializedDateTime.d.ts +2 -2
- package/dist/decorator/dto/serialize/isSerializedDto.d.ts +2 -2
- package/dist/decorator/dto/serialize/serialize.d.ts +1 -1
- package/dist/decorator/dto/serialize/serializeArray.d.ts +2 -2
- package/dist/decorator/dto/serialize/serializeDateTime.d.ts +3 -3
- package/dist/decorator/dto/serialize/serializeDto.d.ts +3 -3
- package/dist/decorator/dto/serialize/serializeObject.d.ts +1 -1
- package/dist/decorator/dto/serialize/serializeUnknown.d.ts +2 -2
- package/dist/decorator/dto/serialize/uuid.d.ts +1 -1
- package/dist/decorator/dto/toJSON.d.ts +4 -4
- package/dist/decorator/index.d.ts +7 -7
- package/dist/dto/BlobResponse.d.ts +5 -5
- package/dist/dto/Paginated.d.ts +8 -8
- package/dist/dto/RequestError.d.ts +9 -0
- package/dist/dto/ValidationError.d.ts +9 -0
- package/dist/dto/index.d.ts +4 -2
- package/dist/http/BaseResponse.d.ts +8 -8
- package/dist/http/BaseService.d.ts +3 -3
- package/dist/http/HttpClient.d.ts +8 -8
- package/dist/http/QueryString.d.ts +11 -12
- package/dist/http/RequestBuilder.d.ts +32 -29
- package/dist/http/helpers.d.ts +2 -1
- package/dist/http/index.d.ts +7 -8
- package/dist/http-client.js +95 -65
- package/dist/http-client.js.map +17 -17
- package/dist/index.d.ts +5 -5
- package/package.json +7 -7
- package/dist/decorator/dto/instance.d.ts +0 -29
- package/dist/decorator/dto/serialize/types.d.ts +0 -3
- package/dist/http/RequestError.d.ts +0 -9
- package/dist/type/index.d.ts +0 -2
package/dist/dto/Paginated.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
export default class Paginated<T> {
|
|
2
|
+
#private;
|
|
3
|
+
get items(): T[];
|
|
4
|
+
get page(): number;
|
|
5
|
+
get pageSize(): number;
|
|
6
|
+
get pages(): number;
|
|
7
|
+
get totalItems(): number;
|
|
8
|
+
constructor(items: T[], page: number, pageSize: number, pages: number, totalItems: number);
|
|
9
9
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HttpStatusCode } from "../type";
|
|
2
|
+
export default class RequestError {
|
|
3
|
+
#private;
|
|
4
|
+
get code(): number;
|
|
5
|
+
get error(): string;
|
|
6
|
+
get errorDescription(): string;
|
|
7
|
+
get statusCode(): HttpStatusCode;
|
|
8
|
+
constructor(code: number, error: string, errorDescription: string, statusCode: HttpStatusCode);
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default class ValidationError {
|
|
2
|
+
#private;
|
|
3
|
+
get code(): number;
|
|
4
|
+
get error(): string;
|
|
5
|
+
get errorDescription(): string;
|
|
6
|
+
get errors(): Record<string, ValidationError>;
|
|
7
|
+
get params(): Record<string, string | number | boolean>;
|
|
8
|
+
constructor(code: number, error: string, errorDescription: string, errors?: Record<string, ValidationError>, params?: Record<string, string | number | boolean>);
|
|
9
|
+
}
|
package/dist/dto/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export { BlobResponse } from
|
|
2
|
-
export { Paginated } from
|
|
1
|
+
export { default as BlobResponse } from "./BlobResponse";
|
|
2
|
+
export { default as Paginated } from "./Paginated";
|
|
3
|
+
export { default as RequestError } from "./RequestError";
|
|
4
|
+
export { default as ValidationError } from "./ValidationError";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { HttpStatusCode } from
|
|
1
|
+
import type { HttpStatusCode } from "../type";
|
|
2
2
|
export default class BaseResponse<T> {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
#private;
|
|
4
|
+
get data(): T;
|
|
5
|
+
get headers(): Headers;
|
|
6
|
+
get ok(): boolean;
|
|
7
|
+
get response(): Response;
|
|
8
|
+
get statusCode(): HttpStatusCode;
|
|
9
|
+
constructor(data: T, response: Response);
|
|
10
10
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import HttpClient from
|
|
2
|
-
import RequestBuilder from
|
|
1
|
+
import HttpClient from "./HttpClient";
|
|
2
|
+
import RequestBuilder from "./RequestBuilder";
|
|
3
3
|
export default class BaseService {
|
|
4
|
-
|
|
4
|
+
protected request(path: string, client?: HttpClient): RequestBuilder;
|
|
5
5
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export default class HttpClient {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
#private;
|
|
3
|
+
get authToken(): string | null;
|
|
4
|
+
set authToken(value: string | null);
|
|
5
|
+
get baseUrl(): string;
|
|
6
|
+
get dataField(): boolean;
|
|
7
|
+
constructor(authToken: string | null, baseUrl: string, dataField?: boolean);
|
|
8
|
+
static get instance(): HttpClient;
|
|
9
|
+
static register(client: HttpClient): void;
|
|
10
10
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
export default class QueryString {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
#private;
|
|
3
|
+
constructor();
|
|
4
|
+
build(): string;
|
|
5
|
+
append(name: string, value: QueryStringValue): QueryString;
|
|
6
|
+
appendArray(name: string, values: QueryStringValue[] | null): QueryString;
|
|
7
|
+
delete(name: string): QueryString;
|
|
8
|
+
get(name: string): string | null;
|
|
9
|
+
getAll(name: string): string[];
|
|
10
|
+
has(name: string): boolean;
|
|
11
|
+
set(name: string, value: QueryStringValue): QueryString;
|
|
12
|
+
static builder(): QueryString;
|
|
13
13
|
}
|
|
14
14
|
type QueryStringValue = boolean | number | string | null;
|
|
15
|
-
export {};
|
|
@@ -1,31 +1,34 @@
|
|
|
1
|
-
import { BlobResponse, Paginated } from
|
|
2
|
-
import type { HttpMethod, HttpStatusCode } from
|
|
3
|
-
import BaseResponse from
|
|
4
|
-
import HttpClient from
|
|
5
|
-
import type QueryString from
|
|
1
|
+
import { BlobResponse, Paginated } from "../dto";
|
|
2
|
+
import type { HttpMethod, HttpStatusCode } from "../type";
|
|
3
|
+
import BaseResponse from "./BaseResponse";
|
|
4
|
+
import HttpClient from "./HttpClient";
|
|
5
|
+
import type QueryString from "./QueryString";
|
|
6
6
|
export default class RequestBuilder {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
7
|
+
#private;
|
|
8
|
+
get client(): HttpClient;
|
|
9
|
+
get options(): RequestInit;
|
|
10
|
+
get path(): string;
|
|
11
|
+
set path(value: string);
|
|
12
|
+
get query(): QueryString | null;
|
|
13
|
+
set query(value: QueryString | null);
|
|
14
|
+
constructor(path: string, client?: HttpClient);
|
|
15
|
+
bearerToken(token?: string): RequestBuilder;
|
|
16
|
+
body(body: BodyInit | FormData | object | null, contentType?: string | null): RequestBuilder;
|
|
17
|
+
header(name: string, value: string): RequestBuilder;
|
|
18
|
+
method(method: HttpMethod): RequestBuilder;
|
|
19
|
+
queryString(queryString: QueryString): RequestBuilder;
|
|
20
|
+
signal(signal?: AbortSignal | null): RequestBuilder;
|
|
21
|
+
fetch<TResult>(): Promise<TResult>;
|
|
22
|
+
fetchBlob(): Promise<BlobResponse>;
|
|
23
|
+
run<TResult extends {}>(): Promise<BaseResponse<TResult>>;
|
|
24
|
+
runAdapter<TResult extends {}>(adapterMethod: (item: object) => TResult): Promise<BaseResponse<TResult>>;
|
|
25
|
+
runArrayAdapter<TResult extends {}>(adapterMethod: (item: object) => TResult): Promise<BaseResponse<TResult[]>>;
|
|
26
|
+
runEmpty(): Promise<BaseResponse<never>>;
|
|
27
|
+
runPaginatedAdapter<TResult extends {}>(adapterMethod: (item: object) => TResult): Promise<BaseResponse<Paginated<TResult>>>;
|
|
28
|
+
runData<TResult>(): Promise<BaseResponse<TResult>>;
|
|
29
|
+
runDataKey<
|
|
30
|
+
TResult extends object,
|
|
31
|
+
TKey extends keyof TResult = keyof TResult
|
|
32
|
+
>(key: TKey): Promise<BaseResponse<TResult[TKey]>>;
|
|
33
|
+
runStatusCode(): Promise<HttpStatusCode>;
|
|
31
34
|
}
|
package/dist/http/helpers.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import RequestError from
|
|
1
|
+
import { RequestError, ValidationError } from "../dto";
|
|
2
2
|
export declare function isRequestError(obj: unknown): obj is RequestError;
|
|
3
3
|
export declare function isUnsanctionedRequest(statusCode: unknown): boolean;
|
|
4
|
+
export declare function isValidationError(obj: unknown): obj is ValidationError;
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import BaseResponse from
|
|
2
|
-
import BaseService from
|
|
3
|
-
import HttpClient from
|
|
4
|
-
import QueryString from
|
|
5
|
-
import RequestBuilder from
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
export { isRequestError, isUnsanctionedRequest } from './helpers';
|
|
1
|
+
import BaseResponse from "./BaseResponse";
|
|
2
|
+
import BaseService from "./BaseService";
|
|
3
|
+
import HttpClient from "./HttpClient";
|
|
4
|
+
import QueryString from "./QueryString";
|
|
5
|
+
import RequestBuilder from "./RequestBuilder";
|
|
6
|
+
export { BaseResponse, BaseService, HttpClient, QueryString, RequestBuilder };
|
|
7
|
+
export { isRequestError, isUnsanctionedRequest, isValidationError } from "./helpers";
|
package/dist/http-client.js
CHANGED
|
@@ -55,31 +55,8 @@ function debounce(fn, interval, $this) {
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
const entries = {};
|
|
61
|
-
do {
|
|
62
|
-
if (obj.name === "") {
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(obj.prototype))) {
|
|
66
|
-
if (["constructor", "clone", "toJSON"].includes(key)) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (!descriptor.get && !descriptor.set) {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
entries[key] = descriptor;
|
|
73
|
-
}
|
|
74
|
-
} while (obj = Object.getPrototypeOf(obj));
|
|
75
|
-
return entries;
|
|
76
|
-
}
|
|
77
|
-
function setObjectMethod_default(obj, key, fn) {
|
|
78
|
-
obj.prototype[key] = fn;
|
|
79
|
-
}
|
|
80
|
-
function setObjectValue_default(obj, key, value) {
|
|
81
|
-
Object.defineProperty(obj, key, { value });
|
|
82
|
-
}
|
|
58
|
+
// src/decorator/dto/index.ts
|
|
59
|
+
import { getPrototypeChain, setObjectMethod, setObjectValue } from "@basmilius/utils";
|
|
83
60
|
|
|
84
61
|
// src/decorator/dto/constant.ts
|
|
85
62
|
var ENABLE_CIRCULAR_LOGGING = false;
|
|
@@ -457,15 +434,15 @@ function toJSON_default() {
|
|
|
457
434
|
// src/decorator/dto/index.ts
|
|
458
435
|
function dto_default(clazz) {
|
|
459
436
|
validate(clazz);
|
|
460
|
-
const descriptors = Object.freeze(
|
|
437
|
+
const descriptors = Object.freeze(getPrototypeChain(clazz));
|
|
461
438
|
const properties = Object.keys(descriptors);
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
439
|
+
setObjectValue(clazz.prototype, DESCRIPTORS, descriptors);
|
|
440
|
+
setObjectValue(clazz.prototype, NAME, clazz.name);
|
|
441
|
+
setObjectValue(clazz.prototype, PROPERTIES, properties);
|
|
442
|
+
setObjectValue(clazz, Symbol.hasInstance, (instance) => typeof instance === "object" && instance?.[NAME] === clazz.name);
|
|
443
|
+
setObjectMethod(clazz, "clone", clone_default);
|
|
444
|
+
setObjectMethod(clazz, "fill", fill_default);
|
|
445
|
+
setObjectMethod(clazz, "toJSON", toJSON_default);
|
|
469
446
|
return proxy(clazz);
|
|
470
447
|
}
|
|
471
448
|
function proxy(clazz) {
|
|
@@ -520,7 +497,7 @@ function deserializeObject_default(obj) {
|
|
|
520
497
|
var CACHE = {};
|
|
521
498
|
function deserializeDto_default([, id, name, state, args]) {
|
|
522
499
|
if (!(name in DTO_CLASS_MAP)) {
|
|
523
|
-
throw new Error(`
|
|
500
|
+
throw new Error(`Cannot restore @dto. Dto ${name} was not found.`);
|
|
524
501
|
}
|
|
525
502
|
if (id in CACHE) {
|
|
526
503
|
return CACHE[id];
|
|
@@ -699,6 +676,67 @@ class Paginated {
|
|
|
699
676
|
Paginated = __legacyDecorateClassTS([
|
|
700
677
|
dto_default
|
|
701
678
|
], Paginated);
|
|
679
|
+
// src/dto/RequestError.ts
|
|
680
|
+
class RequestError {
|
|
681
|
+
get code() {
|
|
682
|
+
return this.#code;
|
|
683
|
+
}
|
|
684
|
+
get error() {
|
|
685
|
+
return this.#error;
|
|
686
|
+
}
|
|
687
|
+
get errorDescription() {
|
|
688
|
+
return this.#errorDescription;
|
|
689
|
+
}
|
|
690
|
+
get statusCode() {
|
|
691
|
+
return this.#statusCode;
|
|
692
|
+
}
|
|
693
|
+
#code;
|
|
694
|
+
#error;
|
|
695
|
+
#errorDescription;
|
|
696
|
+
#statusCode;
|
|
697
|
+
constructor(code, error, errorDescription, statusCode) {
|
|
698
|
+
this.#code = code;
|
|
699
|
+
this.#error = error;
|
|
700
|
+
this.#errorDescription = errorDescription;
|
|
701
|
+
this.#statusCode = statusCode;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
RequestError = __legacyDecorateClassTS([
|
|
705
|
+
dto_default
|
|
706
|
+
], RequestError);
|
|
707
|
+
// src/dto/ValidationError.ts
|
|
708
|
+
class ValidationError {
|
|
709
|
+
get code() {
|
|
710
|
+
return this.#code;
|
|
711
|
+
}
|
|
712
|
+
get error() {
|
|
713
|
+
return this.#error;
|
|
714
|
+
}
|
|
715
|
+
get errorDescription() {
|
|
716
|
+
return this.#errorDescription;
|
|
717
|
+
}
|
|
718
|
+
get errors() {
|
|
719
|
+
return this.#errors;
|
|
720
|
+
}
|
|
721
|
+
get params() {
|
|
722
|
+
return this.#params;
|
|
723
|
+
}
|
|
724
|
+
#code;
|
|
725
|
+
#error;
|
|
726
|
+
#errorDescription;
|
|
727
|
+
#errors;
|
|
728
|
+
#params;
|
|
729
|
+
constructor(code, error, errorDescription, errors, params) {
|
|
730
|
+
this.#code = code;
|
|
731
|
+
this.#error = error;
|
|
732
|
+
this.#errorDescription = errorDescription;
|
|
733
|
+
this.#errors = errors;
|
|
734
|
+
this.#params = params;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
ValidationError = __legacyDecorateClassTS([
|
|
738
|
+
dto_default
|
|
739
|
+
], ValidationError);
|
|
702
740
|
// src/adapter/HttpAdapter.ts
|
|
703
741
|
class HttpAdapter {
|
|
704
742
|
static parsePaginatedAdapter(response, adapterMethod) {
|
|
@@ -716,6 +754,19 @@ class HttpAdapter {
|
|
|
716
754
|
}
|
|
717
755
|
return matches[1].replaceAll("'", "").replaceAll('"', "").replaceAll("/", "-").replaceAll(":", "-");
|
|
718
756
|
}
|
|
757
|
+
static parseRequestError(response, statusCode) {
|
|
758
|
+
return new RequestError(response["code"], response["error"], response["error_description"], statusCode);
|
|
759
|
+
}
|
|
760
|
+
static parseValidationError(response) {
|
|
761
|
+
let errors;
|
|
762
|
+
if (response["errors"]) {
|
|
763
|
+
errors = {};
|
|
764
|
+
Object.entries(response["errors"]).forEach(([key, value]) => {
|
|
765
|
+
errors[key] = HttpAdapter.parseValidationError(value);
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
return new ValidationError(response["code"], response["error"], response["error_description"], errors, response["params"]);
|
|
769
|
+
}
|
|
719
770
|
}
|
|
720
771
|
HttpAdapter = __legacyDecorateClassTS([
|
|
721
772
|
adapter_default
|
|
@@ -782,35 +833,6 @@ class HttpClient {
|
|
|
782
833
|
}
|
|
783
834
|
}
|
|
784
835
|
|
|
785
|
-
// src/http/RequestError.ts
|
|
786
|
-
class RequestError {
|
|
787
|
-
get code() {
|
|
788
|
-
return this.#code;
|
|
789
|
-
}
|
|
790
|
-
get error() {
|
|
791
|
-
return this.#error;
|
|
792
|
-
}
|
|
793
|
-
get errorDescription() {
|
|
794
|
-
return this.#errorDescription;
|
|
795
|
-
}
|
|
796
|
-
get statusCode() {
|
|
797
|
-
return this.#statusCode;
|
|
798
|
-
}
|
|
799
|
-
#code;
|
|
800
|
-
#error;
|
|
801
|
-
#errorDescription;
|
|
802
|
-
#statusCode;
|
|
803
|
-
constructor(code, error, errorDescription, statusCode) {
|
|
804
|
-
this.#code = code;
|
|
805
|
-
this.#error = error;
|
|
806
|
-
this.#errorDescription = errorDescription;
|
|
807
|
-
this.#statusCode = statusCode;
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
RequestError = __legacyDecorateClassTS([
|
|
811
|
-
dto_default
|
|
812
|
-
], RequestError);
|
|
813
|
-
|
|
814
836
|
// src/http/RequestBuilder.ts
|
|
815
837
|
class RequestBuilder {
|
|
816
838
|
get client() {
|
|
@@ -941,7 +963,10 @@ class RequestBuilder {
|
|
|
941
963
|
if (response.headers.has("content-type") && response.headers.get("content-type").startsWith("application/json")) {
|
|
942
964
|
const data2 = await response.json();
|
|
943
965
|
if ("code" in data2 && "error" in data2 && "error_description" in data2) {
|
|
944
|
-
|
|
966
|
+
if ("errors" in data2) {
|
|
967
|
+
throw HttpAdapter.parseValidationError(data2);
|
|
968
|
+
}
|
|
969
|
+
throw HttpAdapter.parseRequestError(data2, response.status);
|
|
945
970
|
}
|
|
946
971
|
if (dataField && "data" in data2) {
|
|
947
972
|
return new BaseResponse(data2.data, response);
|
|
@@ -1033,10 +1058,14 @@ function isUnsanctionedRequest(statusCode) {
|
|
|
1033
1058
|
}
|
|
1034
1059
|
return statusCode === 403 || statusCode === 401;
|
|
1035
1060
|
}
|
|
1061
|
+
function isValidationError(obj) {
|
|
1062
|
+
return obj instanceof ValidationError;
|
|
1063
|
+
}
|
|
1036
1064
|
export {
|
|
1037
1065
|
serialize_default as serialize,
|
|
1038
1066
|
markDtoDirty_default as markDtoDirty,
|
|
1039
1067
|
markDtoClean_default as markDtoClean,
|
|
1068
|
+
isValidationError,
|
|
1040
1069
|
isUnsanctionedRequest,
|
|
1041
1070
|
isRequestError,
|
|
1042
1071
|
isDtoDirty_default as isDtoDirty,
|
|
@@ -1050,6 +1079,7 @@ export {
|
|
|
1050
1079
|
bound_default as bound,
|
|
1051
1080
|
assertDto_default as assertDto,
|
|
1052
1081
|
adapter_default as adapter,
|
|
1082
|
+
ValidationError,
|
|
1053
1083
|
RequestError,
|
|
1054
1084
|
RequestBuilder,
|
|
1055
1085
|
QueryString,
|
|
@@ -1061,5 +1091,5 @@ export {
|
|
|
1061
1091
|
BaseResponse
|
|
1062
1092
|
};
|
|
1063
1093
|
|
|
1064
|
-
//# debugId=
|
|
1094
|
+
//# debugId=AD0CA21D25D97D8A64756E2164756E21
|
|
1065
1095
|
//# sourceMappingURL=http-client.js.map
|