{"version":3,"sources":["../../src/experimental/tryOrFail.ts"],"names":["tryOrFail","fn","e","HttpException","statusCode","cause","isObjectWithErrorStatusCode","HttpInternalServerError","isErrorWithErrorStatusCode","createHttpException"],"mappings":"uHAQO,IAAMA,CAAAA,CAAY,MACvBC,CAAAA,EAEOA,CAAAA,EAAG,CAAE,KAAA,CAAOC,CAAAA,EAAM,CACvB,GAAIA,CAAAA,YAAaC,mBAAAA,CACf,MAAMD,CAAAA,CAER,GAAM,CAAE,UAAA,CAAAE,CAAAA,CAAY,KAAA,CAAAC,CAAM,CAAA,CAAI,CAC5B,UAAA,CAAYC,mBAAAA,CAA4BJ,CAAC,CAAA,CACrCA,CAAAA,CAAE,UAAA,CACFK,mBAAAA,CAAwB,OAC5B,GAAIC,mBAAAA,CAA2BN,CAAC,CAAA,CAC5B,CACE,KAAA,CAAOA,CACT,CAAA,CACA,EACN,CAAA,CACA,MAAMO,mBAAAA,CAAoBL,CAAAA,CAAY,CACpC,OAAA,CAASF,CAAAA,YAAa,KAAA,EAASA,CAAAA,CAAE,OAAA,GAAY,EAAA,CAAKA,CAAAA,CAAE,OAAA,CAAU,MAAA,CAC9D,KAAA,CAAAG,CACF,CAAC,CACH,CAAC","file":"index.cjs","sourcesContent":["import { HttpException } from '../base/HttpException';\nimport { createHttpException } from '../factory/createHttpException';\nimport { HttpInternalServerError } from '../server/HttpInternalServerError';\nimport { isErrorWithErrorStatusCode } from '../typeguards/isErrorWithErrorStatusCode';\nimport { isObjectWithErrorStatusCode } from '../typeguards/isObjectWithErrorStatusCode';\n\ntype AsyncFn<A extends unknown[], O> = (...args: A) => Promise<O>;\n\nexport const tryOrFail = async <T extends AsyncFn<unknown[], unknown>>(\n  fn: T\n): Promise<ReturnType<T>> => {\n  return fn().catch((e) => {\n    if (e instanceof HttpException) {\n      throw e;\n    }\n    const { statusCode, cause } = {\n      statusCode: isObjectWithErrorStatusCode(e)\n        ? e.statusCode\n        : HttpInternalServerError.STATUS,\n      ...(isErrorWithErrorStatusCode(e)\n        ? {\n            cause: e,\n          }\n        : {}),\n    };\n    throw createHttpException(statusCode, {\n      message: e instanceof Error && e.message !== '' ? e.message : undefined,\n      cause,\n    });\n  }) as Awaited<ReturnType<T>>;\n};\n"]}