@bluemarble/bm-components 1.0.0 → 1.1.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/index.mjs CHANGED
@@ -3969,7 +3969,11 @@ var HttpError = class extends Error {
3969
3969
 
3970
3970
  // src/helpers/apiHelper/index.ts
3971
3971
  var ApiHelper = class _ApiHelper {
3972
- onFinally(req) {
3972
+ onFinally(req, res) {
3973
+ return __async(this, null, function* () {
3974
+ });
3975
+ }
3976
+ onError(req, res) {
3973
3977
  return __async(this, null, function* () {
3974
3978
  });
3975
3979
  }
@@ -3977,6 +3981,8 @@ var ApiHelper = class _ApiHelper {
3977
3981
  this.middlewares = ((props == null ? void 0 : props.middlewares) || []).reverse();
3978
3982
  this.onFinally = props.onFinally || (() => __async(this, null, function* () {
3979
3983
  }));
3984
+ this.onError = props.onError || (() => __async(this, null, function* () {
3985
+ }));
3980
3986
  }
3981
3987
  setMiddlewares(middlewares) {
3982
3988
  this.middlewares = middlewares.reverse();
@@ -3998,15 +4004,18 @@ var ApiHelper = class _ApiHelper {
3998
4004
  } catch (error) {
3999
4005
  if (error instanceof HttpError)
4000
4006
  return res.status(error.status).json(error.message);
4001
- if (process.env.NODE_ENV === "production")
4002
- return res.status(500).json({
4007
+ if (process.env.NODE_ENV === "production") {
4008
+ res.status(500).json({
4003
4009
  code: "internal.error",
4004
4010
  error: "Erro interno do servidor",
4005
4011
  details: error
4006
4012
  });
4013
+ return this.onError(req, res);
4014
+ }
4015
+ this.onError(req, res);
4007
4016
  throw new Error(error);
4008
4017
  } finally {
4009
- yield this.onFinally(req);
4018
+ yield this.onFinally(req, res);
4010
4019
  }
4011
4020
  });
4012
4021
  }