framework-do-dede 0.0.53 → 0.0.55

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.
@@ -60,8 +60,10 @@ export default class ControllerHandler {
60
60
  const capturedError = this.extractError(error, httpServer);
61
61
  requestMetrics.error = capturedError;
62
62
  input.setStatus(capturedError.statusCode);
63
- console.log('capturedError = ', capturedError);
64
- return capturedError;
63
+ return {
64
+ message: capturedError.message,
65
+ statusCode: capturedError.statusCode
66
+ };
65
67
  }
66
68
  finally {
67
69
  requestMetrics.endTime = performance.now();
@@ -74,12 +76,6 @@ export default class ControllerHandler {
74
76
  }
75
77
  httpServer.listen(port);
76
78
  }
77
- // if (error instanceof ServerError) {
78
- // res.status(error.getStatusCode())
79
- // throw error;
80
- // }
81
- // res.status(500)
82
- // throw new InternalServerError(error.message, this.defaultMessageError)
83
79
  registryControllers() {
84
80
  const registryControllers = Registry.resolve('controllers');
85
81
  const controllers = [];
@@ -24,7 +24,7 @@ export default abstract class HttpServer {
24
24
  use(middleware: CallableFunction): HttpServer;
25
25
  register(httpServerParams: HttpServerParams, handler: CallableFunction): void;
26
26
  setDefaultMessageError(message: string): void;
27
- getDefaultMessageError(): string;
27
+ getDefaultMessageError(): string | undefined;
28
28
  listen(port: number): void;
29
29
  private mountRoute;
30
30
  private elysia;
@@ -1,9 +1,8 @@
1
1
  import { FrameworkError } from "./FrameworkError";
2
- import { InternalServerError, ServerError } from "./ServerError";
3
2
  export default class HttpServer {
4
3
  framework;
5
4
  frameworkName;
6
- defaultMessageError = '';
5
+ defaultMessageError;
7
6
  constructor(framework, frameworkName) {
8
7
  if (frameworkName !== 'elysia' && frameworkName !== 'express')
9
8
  throw new FrameworkError('Framework not supported');
@@ -58,34 +57,14 @@ export default class HttpServer {
58
57
  const method = httpServerParams.method;
59
58
  this.framework[method](route, async (request, res) => {
60
59
  request.headers['ip'] = request.ip;
61
- try {
62
- const output = await handler({
63
- setStatus: (statusCode) => res.status(statusCode),
64
- headers: request.headers,
65
- query: request.query,
66
- params: request.params,
67
- body: request.body
68
- });
69
- return res.status(httpServerParams.statusCode ?? 200).json(output);
70
- }
71
- catch (error) {
72
- if (error instanceof ServerError) {
73
- res.status(error.getStatusCode());
74
- throw error;
75
- }
76
- res.status(500);
77
- throw new InternalServerError(error.message, this.defaultMessageError);
78
- // if (error instanceof ServerError) {
79
- // return res.status(error.getStatusCode()).json({
80
- // error: error.message,
81
- // statusCode: error.getStatusCode()
82
- // })
83
- // }
84
- // return res.status(500).json({
85
- // error: this.defaultMessageError,
86
- // statusCode: 500
87
- // })
88
- }
60
+ const output = await handler({
61
+ setStatus: (statusCode) => res.status(statusCode),
62
+ headers: request.headers,
63
+ query: request.query,
64
+ params: request.params,
65
+ body: request.body
66
+ });
67
+ return res.status(httpServerParams.statusCode ?? 200).json(output);
89
68
  });
90
69
  }
91
70
  }
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Dede, Register as DedeRegister, Options as DedeOptions } from './dede';
2
2
  import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject, Restrict, Metrics, OffConsoleLog } from './decorators';
3
3
  import { BadRequest, Conflict, Forbidden, HttpServer, NotFound, ServerError, Unauthorized, UnprocessableEntity } from './http';
4
- import { Validation, HttpMiddleware, UseCase, CreateRepository, DeleteRepository, UpdateRepository, RestoreRepository, RequestMetricsHandler, RequestData, RequestMetrics } from './protocols';
4
+ import { Validation, HttpMiddleware, UseCase, CreateRepository, DeleteRepository, UpdateRepository, RestoreRepository, RequestMetricsHandler, RequestData, RequestMetrics, HttpServerError } from './protocols';
5
5
  import { Entity } from './domain/Entity';
6
6
  declare class UseCaseHandler {
7
7
  static load<T extends UseCase<any, any>>(useCaseClass: new (...args: any[]) => T, request?: RequestData): T;
8
8
  }
9
- export { UseCase, HttpMiddleware, Validation, RequestMetricsHandler, RequestMetrics, CreateRepository, DeleteRepository, UpdateRepository, RestoreRepository, RequestData, Dede, DedeRegister, DedeOptions, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject, Entity, Restrict, Metrics, OffConsoleLog };
9
+ export { UseCase, HttpMiddleware, Validation, RequestMetricsHandler, RequestMetrics, HttpServerError, CreateRepository, DeleteRepository, UpdateRepository, RestoreRepository, RequestData, Dede, DedeRegister, DedeOptions, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject, Entity, Restrict, Metrics, OffConsoleLog };
@@ -0,0 +1,5 @@
1
+ import { HttpStatusCode } from "../http/HttpServer";
2
+ export interface HttpServerError {
3
+ message: string;
4
+ statusCode: HttpStatusCode;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -8,4 +8,5 @@ import type { RestoreRepository } from './RestoreRepository';
8
8
  import type { RequestMetricsHandler } from './RequestMetricsHandler';
9
9
  import type { RequestData } from './RequestData';
10
10
  import type { RequestMetrics } from './RequestMetrics';
11
- export type { RequestData, RequestMetrics, HttpMiddleware, UseCase, Validation, CreateRepository, DeleteRepository, UpdateRepository, RestoreRepository, RequestMetricsHandler };
11
+ import type { HttpServerError } from './HttpServerError';
12
+ export type { RequestData, RequestMetrics, HttpMiddleware, UseCase, Validation, CreateRepository, DeleteRepository, UpdateRepository, RestoreRepository, RequestMetricsHandler, HttpServerError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "framework-do-dede",
3
- "version": "0.0.53",
3
+ "version": "0.0.55",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",