@buka/nestjs-kit 4.4.8 → 4.4.10

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/index.mjs CHANGED
@@ -1591,7 +1591,13 @@ function getObjectSchema(classRef) {
1591
1591
  if (isRelation) if (isCollection) {
1592
1592
  const sub = getObjectSchema(propertyMetadata.association.type());
1593
1593
  const operators = getCollectionOperators(classRef, propertyKey);
1594
- for (const operator of operators) properties[operator] = sub;
1594
+ const wrapper = {
1595
+ type: "object",
1596
+ properties: {},
1597
+ additionalProperties: false
1598
+ };
1599
+ for (const operator of operators) wrapper.properties[operator] = sub;
1600
+ properties[propertyKey] = wrapper;
1595
1601
  } else properties[propertyKey] = getObjectSchema(propertyMetadata.association.type());
1596
1602
  else {
1597
1603
  const propertySchema = {
@@ -8403,8 +8409,14 @@ function throwOnResponseError(options) {
8403
8409
  if (!ctx.response || ctx.response.status >= 200 && ctx.response.status < 400) return;
8404
8410
  const response = ctx.response;
8405
8411
  if (!response.headers.get("content-type")?.includes("application/json")) throw createExceptionByStatusCode(response);
8406
- const body = await response.json();
8407
- if (body !== null && typeof body === "object" && "error" in body) try {
8412
+ let body;
8413
+ try {
8414
+ body = await response.json();
8415
+ } catch (err) {
8416
+ if (debug) logger.debug("响应体 JSON 解析失败,降级为状态码异常", err instanceof Error ? err.stack : err);
8417
+ throw createExceptionByStatusCode(response);
8418
+ }
8419
+ if (body !== null && typeof body === "object" && "error" in body) {
8408
8420
  const { error } = body;
8409
8421
  const exceptionOptions = {
8410
8422
  code: error.code,
@@ -8416,13 +8428,13 @@ function throwOnResponseError(options) {
8416
8428
  404
8417
8429
  ].includes(response.status)
8418
8430
  };
8419
- if (errorDispatchers && error.code in errorDispatchers) {
8431
+ if (errorDispatchers && error.code in errorDispatchers) try {
8420
8432
  const ExceptionClass = errorDispatchers[error.code];
8421
8433
  throw new ExceptionClass(response.status, error.message, exceptionOptions);
8434
+ } catch (caught) {
8435
+ if (debug) logger.debug("自定义异常派发失败,降级为 BukaRequestException", caught instanceof Error ? caught.stack : caught);
8422
8436
  }
8423
8437
  throw new BukaRequestException(response.status, error.message, exceptionOptions);
8424
- } catch (caught) {
8425
- if (debug) logger.debug("解析响应错误体失败,降级为通用异常", caught instanceof Error ? caught.stack : caught);
8426
8438
  }
8427
8439
  throw createExceptionByStatusCode(response);
8428
8440
  };