@azure-net/kit 6.0.0-next.12 → 6.0.0-next.13

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.
@@ -1,3 +1,4 @@
1
+ import { type RequestErrors, SchemaFail } from '../../delivery/schema/Schema.js';
1
2
  export type SearchParamsInit = string | string[][] | Record<string, string> | URLSearchParams | undefined;
2
3
  export type SearchParamsOption = SearchParamsInit | Record<string, string | number | boolean | undefined> | Array<Array<string | number | boolean>>;
3
4
  export declare enum HttpInstanceFetchMethods {
@@ -24,6 +25,7 @@ export interface IHttpServiceError<T = unknown> {
24
25
  message: string;
25
26
  status: number;
26
27
  data?: T;
28
+ validation?: unknown;
27
29
  }
28
30
  export declare class HttpServiceResponse<T> implements IHttpServiceResponse<T> {
29
31
  headers: Record<string, string>;
@@ -45,7 +47,10 @@ export declare class HttpServiceError<T> extends Error implements IHttpServiceEr
45
47
  type: HttpErrorTypes;
46
48
  original?: Error;
47
49
  response?: Response;
50
+ validation?: SchemaFail<Record<string, unknown>>;
48
51
  constructor({ status, data, message, original, type, response }: Partial<IHttpServiceError<T>>);
52
+ addAsValidation(validation: RequestErrors<Record<string, unknown>>): void;
53
+ getSelfTypedData<T = unknown>(): T;
49
54
  }
50
55
  export interface IHttpInstanceNormalizedRequest {
51
56
  url: string | URL;
@@ -1,5 +1,6 @@
1
1
  import { BROWSER } from '../../external/tools/index.js';
2
2
  import { RequestContext } from '../../shared/request-context/Internal.js';
3
+ import { SchemaFail } from '../../delivery/schema/Schema.js';
3
4
  export var HttpInstanceFetchMethods;
4
5
  (function (HttpInstanceFetchMethods) {
5
6
  HttpInstanceFetchMethods["GET"] = "GET";
@@ -38,6 +39,7 @@ export class HttpServiceError extends Error {
38
39
  type;
39
40
  original;
40
41
  response;
42
+ validation;
41
43
  constructor({ status = 500, data, message = 'unknown error', original, type = HttpErrorTypes.Internal, response }) {
42
44
  super(message);
43
45
  this.status = status;
@@ -47,6 +49,12 @@ export class HttpServiceError extends Error {
47
49
  this.response = response;
48
50
  this.type = type;
49
51
  }
52
+ addAsValidation(validation) {
53
+ this.validation = new SchemaFail(validation);
54
+ }
55
+ getSelfTypedData() {
56
+ return this.data;
57
+ }
50
58
  }
51
59
  const stringifyJsonFunc = (data) => {
52
60
  try {
@@ -52,6 +52,7 @@ export class AppError extends Error {
52
52
  this.type = ErrorTypes.Http;
53
53
  this.external = this.error.type === HttpErrorTypes.External;
54
54
  this.statusCode = this.error.status;
55
+ this.validation = this.error?.validation?.getSelfTypedData();
55
56
  break;
56
57
  case this.error instanceof SchemaFail:
57
58
  this.type = ErrorTypes.Schema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-net/kit",
3
- "version": "6.0.0-next.12",
3
+ "version": "6.0.0-next.13",
4
4
  "license": "MIT",
5
5
  "author": "Pixel1917",
6
6
  "description": "Universal toolkit and library collection, developed as part of the Azure-net ecosystem",