vovk 3.0.0-draft.451 → 3.0.0-draft.453

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,9 +1,9 @@
1
1
  import { VovkHandlerSchema } from '../types';
2
2
  import type { VovkStreamAsyncIterable } from './types';
3
3
  import '../utils/shim';
4
- export declare const DEFAULT_ERROR_MESSAGE = "Unknown error at defaultStreamHandler";
4
+ export declare const DEFAULT_ERROR_MESSAGE = "An unknown error at defaultStreamHandler";
5
5
  export declare const defaultStreamHandler: ({ response, abortController, }: {
6
6
  response: Response;
7
7
  abortController: AbortController;
8
8
  schema: VovkHandlerSchema;
9
- }) => Promise<VovkStreamAsyncIterable<unknown>>;
9
+ }) => VovkStreamAsyncIterable<unknown>;
@@ -4,18 +4,18 @@ exports.defaultStreamHandler = exports.DEFAULT_ERROR_MESSAGE = void 0;
4
4
  const types_1 = require("../types");
5
5
  const HttpException_1 = require("../HttpException");
6
6
  require("../utils/shim");
7
- exports.DEFAULT_ERROR_MESSAGE = 'Unknown error at defaultStreamHandler';
8
- const defaultStreamHandler = async ({ response, abortController, }) => {
7
+ exports.DEFAULT_ERROR_MESSAGE = 'An unknown error at defaultStreamHandler';
8
+ const defaultStreamHandler = ({ response, abortController, }) => {
9
9
  if (!response.ok) {
10
- let result;
11
- try {
12
- result = await response.json();
13
- }
14
- catch {
15
- // ignore parsing errors
16
- }
10
+ response
11
+ .json()
12
+ .then((res) => {
13
+ throw new HttpException_1.HttpException(response.status, res.message ?? exports.DEFAULT_ERROR_MESSAGE);
14
+ })
15
+ .catch(() => {
16
+ throw new HttpException_1.HttpException(response.status, exports.DEFAULT_ERROR_MESSAGE);
17
+ });
17
18
  // handle server errors
18
- throw new HttpException_1.HttpException(response.status, result.message ?? exports.DEFAULT_ERROR_MESSAGE);
19
19
  }
20
20
  if (!response.body)
21
21
  throw new HttpException_1.HttpException(types_1.HttpStatus.NULL, 'Stream body is falsy. Check your controller code.');
@@ -78,12 +78,11 @@ function createFetcher({ prepareRequestInit, transformResponse, onSuccess, onErr
78
78
  respData = defaultStreamHandler({ response, abortController, schema });
79
79
  }
80
80
  else if (contentType?.startsWith('application/json')) {
81
- respData = defaultHandler({ response, schema });
81
+ respData = await defaultHandler({ response, schema });
82
82
  }
83
83
  else {
84
84
  respData = response;
85
85
  }
86
- respData = await respData;
87
86
  respData = transformResponse ? await transformResponse(respData, inputOptions, response, requestInit) : respData;
88
87
  await onSuccess?.(respData, inputOptions, response, requestInit);
89
88
  return [respData, response];
@@ -1,9 +1,9 @@
1
1
  import { VovkHandlerSchema } from '../types';
2
2
  import type { VovkStreamAsyncIterable } from './types';
3
3
  import '../utils/shim';
4
- export declare const DEFAULT_ERROR_MESSAGE = "Unknown error at defaultStreamHandler";
4
+ export declare const DEFAULT_ERROR_MESSAGE = "An unknown error at defaultStreamHandler";
5
5
  export declare const defaultStreamHandler: ({ response, abortController, }: {
6
6
  response: Response;
7
7
  abortController: AbortController;
8
8
  schema: VovkHandlerSchema;
9
- }) => Promise<VovkStreamAsyncIterable<unknown>>;
9
+ }) => VovkStreamAsyncIterable<unknown>;
@@ -4,18 +4,18 @@ exports.defaultStreamHandler = exports.DEFAULT_ERROR_MESSAGE = void 0;
4
4
  const types_1 = require("../types");
5
5
  const HttpException_1 = require("../HttpException");
6
6
  require("../utils/shim");
7
- exports.DEFAULT_ERROR_MESSAGE = 'Unknown error at defaultStreamHandler';
8
- const defaultStreamHandler = async ({ response, abortController, }) => {
7
+ exports.DEFAULT_ERROR_MESSAGE = 'An unknown error at defaultStreamHandler';
8
+ const defaultStreamHandler = ({ response, abortController, }) => {
9
9
  if (!response.ok) {
10
- let result;
11
- try {
12
- result = await response.json();
13
- }
14
- catch {
15
- // ignore parsing errors
16
- }
10
+ response
11
+ .json()
12
+ .then((res) => {
13
+ throw new HttpException_1.HttpException(response.status, res.message ?? exports.DEFAULT_ERROR_MESSAGE);
14
+ })
15
+ .catch(() => {
16
+ throw new HttpException_1.HttpException(response.status, exports.DEFAULT_ERROR_MESSAGE);
17
+ });
17
18
  // handle server errors
18
- throw new HttpException_1.HttpException(response.status, result.message ?? exports.DEFAULT_ERROR_MESSAGE);
19
19
  }
20
20
  if (!response.body)
21
21
  throw new HttpException_1.HttpException(types_1.HttpStatus.NULL, 'Stream body is falsy. Check your controller code.');
@@ -78,12 +78,11 @@ function createFetcher({ prepareRequestInit, transformResponse, onSuccess, onErr
78
78
  respData = defaultStreamHandler({ response, abortController, schema });
79
79
  }
80
80
  else if (contentType?.startsWith('application/json')) {
81
- respData = defaultHandler({ response, schema });
81
+ respData = await defaultHandler({ response, schema });
82
82
  }
83
83
  else {
84
84
  respData = response;
85
85
  }
86
- respData = await respData;
87
86
  respData = transformResponse ? await transformResponse(respData, inputOptions, response, requestInit) : respData;
88
87
  await onSuccess?.(respData, inputOptions, response, requestInit);
89
88
  return [respData, response];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "3.0.0-draft.451",
3
+ "version": "3.0.0-draft.453",
4
4
  "main": "./cjs/index.js",
5
5
  "module": "./mjs/index.js",
6
6
  "types": "./mjs/index.d.ts",