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