@expressots/core 1.4.0 → 1.4.2
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/LICENSE.md +21 -21
- package/README.md +61 -65
- package/lib/CHANGELOG.md +192 -167
- package/lib/README.md +61 -65
- package/lib/cjs/controller/base-controller.js +2 -17
- package/lib/cjs/error/error-handler-middleware.js +1 -3
- package/lib/cjs/error/index.js +1 -3
- package/lib/cjs/error/report.js +39 -5
- package/lib/cjs/logger/general-logger.js +2 -2
- package/lib/cjs/types/controller/base-controller.d.ts.map +1 -1
- package/lib/cjs/types/error/error-handler-middleware.d.ts +3 -3
- package/lib/cjs/types/error/error-handler-middleware.d.ts.map +1 -1
- package/lib/cjs/types/error/index.d.ts +0 -1
- package/lib/cjs/types/error/index.d.ts.map +1 -1
- package/lib/cjs/types/error/report.d.ts +23 -6
- package/lib/cjs/types/error/report.d.ts.map +1 -1
- package/lib/esm/controller/base-controller.js +2 -17
- package/lib/esm/error/error-handler-middleware.js +1 -3
- package/lib/esm/error/index.js +0 -1
- package/lib/esm/error/report.js +39 -5
- package/lib/esm/logger/general-logger.js +2 -2
- package/lib/esm/types/controller/base-controller.d.ts.map +1 -1
- package/lib/esm/types/error/error-handler-middleware.d.ts +3 -3
- package/lib/esm/types/error/error-handler-middleware.d.ts.map +1 -1
- package/lib/esm/types/error/index.d.ts +0 -1
- package/lib/esm/types/error/index.d.ts.map +1 -1
- package/lib/esm/types/error/report.d.ts +23 -6
- package/lib/esm/types/error/report.d.ts.map +1 -1
- package/lib/package.json +2 -2
- package/package.json +2 -2
- package/lib/cjs/error/application-error.js +0 -37
- package/lib/cjs/types/error/application-error.d.ts +0 -18
- package/lib/cjs/types/error/application-error.d.ts.map +0 -1
- package/lib/esm/error/application-error.js +0 -36
- package/lib/esm/types/error/application-error.d.ts +0 -18
- package/lib/esm/types/error/application-error.d.ts.map +0 -1
package/lib/README.md
CHANGED
|
@@ -1,65 +1,61 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<a href="https://expresso-ts.com/" target="blank"><img src="https://github.com/expressots/expressots/blob/main/media/expressots.png" width="120" alt="Expresso TS Logo" /></a>
|
|
3
|
-
</p>
|
|
4
|
-
|
|
5
|
-
# Expresso TS
|
|
6
|
-
|
|
7
|
-
A Typescript + [Node.js]("https://nodejs.org/en/") lightweight framework for quick building scalable, easy to read and maintain, server-side applications 🚀
|
|
8
|
-
|
|
9
|
-
## Philosophy
|
|
10
|
-
|
|
11
|
-
ExpressoTS is a developer-friendly framework designed to streamline the process of building server-side applications. With a focus on readability, maintainability, and scalability, ExpressoTS aims to simplify the development process by providing a clear and concise structure.
|
|
12
|
-
|
|
13
|
-
Gone are the days of tedious setup tasks such as configuring logging systems, handling authentication, and connecting to databases. With ExpressoTS, developers can focus on what really matters - writing code. The framework takes care of the repetitive and time-consuming aspects of development, allowing developers to work more efficiently.
|
|
14
|
-
|
|
15
|
-
One of the key features of Expresso TS is its flexible and extensible architecture. The framework provides a simple but powerful dependency injection system that enables developers to quickly and easily extend its functionality by creating and adding providers. This allows developers to seamlessly integrate new features throughout the entire application without having to worry about the complexities of integration.
|
|
16
|
-
|
|
17
|
-
Whether you're building a simple API or a complex enterprise application, Expresso TS can help you deliver your project on time and on budget. With a comprehensive set of tools and features, Expresso TS makes it easy to build high-quality, scalable, and maintainable server-side applications.
|
|
18
|
-
|
|
19
|
-
## Getting Started
|
|
20
|
-
|
|
21
|
-
- Here is our [Official Documentation](https://expresso-ts.com/)
|
|
22
|
-
- Checkout our [First Steps documentation](https://expresso-ts.com/docs/overview/first-steps)
|
|
23
|
-
- Our [CLI Documentation](https://expresso-ts.com/docs/category/cli)
|
|
24
|
-
|
|
25
|
-
## Questions
|
|
26
|
-
|
|
27
|
-
For questions and support please use the Official [Discord Channel](https://discord.com/invite/PyPJfGK). We have a very active community there, that will be happy to help you. Post your questions in the channel called **HELP EXPRESSO TS** and forum called **help**.
|
|
28
|
-
|
|
29
|
-
## Issues
|
|
30
|
-
|
|
31
|
-
The [Issue Reporting Channel](https://github.com/expressots/expressots/issues) is for bug report and feature request **only**.
|
|
32
|
-
|
|
33
|
-
Before you create an issue, please make sure you read the [Contribution Guidelines](CONTRIBUTING.md).
|
|
34
|
-
|
|
35
|
-
## Support
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
- Become a sponsor on GitHub
|
|
40
|
-
- Follow the organization on GitHub and Star the project
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
- [
|
|
49
|
-
- [
|
|
50
|
-
- [
|
|
51
|
-
- [
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
## License
|
|
64
|
-
|
|
65
|
-
ExpressoTS is **[MIT licensed](LICENSE.md)**
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://expresso-ts.com/" target="blank"><img src="https://github.com/expressots/expressots/blob/main/media/expressots.png" width="120" alt="Expresso TS Logo" /></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# Expresso TS
|
|
6
|
+
|
|
7
|
+
A Typescript + [Node.js]("https://nodejs.org/en/") lightweight framework for quick building scalable, easy to read and maintain, server-side applications 🚀
|
|
8
|
+
|
|
9
|
+
## Philosophy
|
|
10
|
+
|
|
11
|
+
ExpressoTS is a developer-friendly framework designed to streamline the process of building server-side applications. With a focus on readability, maintainability, and scalability, ExpressoTS aims to simplify the development process by providing a clear and concise structure.
|
|
12
|
+
|
|
13
|
+
Gone are the days of tedious setup tasks such as configuring logging systems, handling authentication, and connecting to databases. With ExpressoTS, developers can focus on what really matters - writing code. The framework takes care of the repetitive and time-consuming aspects of development, allowing developers to work more efficiently.
|
|
14
|
+
|
|
15
|
+
One of the key features of Expresso TS is its flexible and extensible architecture. The framework provides a simple but powerful dependency injection system that enables developers to quickly and easily extend its functionality by creating and adding providers. This allows developers to seamlessly integrate new features throughout the entire application without having to worry about the complexities of integration.
|
|
16
|
+
|
|
17
|
+
Whether you're building a simple API or a complex enterprise application, Expresso TS can help you deliver your project on time and on budget. With a comprehensive set of tools and features, Expresso TS makes it easy to build high-quality, scalable, and maintainable server-side applications.
|
|
18
|
+
|
|
19
|
+
## Getting Started
|
|
20
|
+
|
|
21
|
+
- Here is our [Official Documentation](https://expresso-ts.com/)
|
|
22
|
+
- Checkout our [First Steps documentation](https://expresso-ts.com/docs/overview/first-steps)
|
|
23
|
+
- Our [CLI Documentation](https://expresso-ts.com/docs/category/cli)
|
|
24
|
+
|
|
25
|
+
## Questions
|
|
26
|
+
|
|
27
|
+
For questions and support please use the Official [Discord Channel](https://discord.com/invite/PyPJfGK). We have a very active community there, that will be happy to help you. Post your questions in the channel called **HELP EXPRESSO TS** and forum called **help**.
|
|
28
|
+
|
|
29
|
+
## Issues
|
|
30
|
+
|
|
31
|
+
The [Issue Reporting Channel](https://github.com/expressots/expressots/issues) is for bug report and feature request **only**.
|
|
32
|
+
|
|
33
|
+
Before you create an issue, please make sure you read the [Contribution Guidelines](CONTRIBUTING.md).
|
|
34
|
+
|
|
35
|
+
## Support the project
|
|
36
|
+
|
|
37
|
+
Expresso TS is an MIT-licensed open source project. It's an independent project with ongoing development made possible thanks to your support. If you'd like to help, please consider:
|
|
38
|
+
|
|
39
|
+
- Become a sponsor on **[Sponsor no GitHub](https://github.com/sponsors/expressots)**
|
|
40
|
+
- Follow the **[organization](https://github.com/expressots)** on GitHub and Star ⭐ the project
|
|
41
|
+
- Subscribe to the Twitch channel: **[Richard Zampieri](https://www.twitch.tv/richardzampieri)**
|
|
42
|
+
- Join our **[Discord](https://discord.com/invite/PyPJfGK)**
|
|
43
|
+
- Contribute submitting **[issues and pull requests](https://github.com/expressots/expressots/issues/new/choose)**
|
|
44
|
+
- Share the project with your friends and colleagues
|
|
45
|
+
|
|
46
|
+
## Contributors
|
|
47
|
+
|
|
48
|
+
- [Daniel Boll](https://github.com/daniel-boll)
|
|
49
|
+
- [Felipe Fontana](https://github.com/f0ntana)
|
|
50
|
+
- [Juliano Soares](https://github.com/juliano-soares)
|
|
51
|
+
- [Vitor Caminha](https://github.com/VitorCaminha)
|
|
52
|
+
- [Ariel Betti](https://github.com/ArielBetti)
|
|
53
|
+
- [Rodrigo da Hora](https://github.com/dahorarodrigo)
|
|
54
|
+
|
|
55
|
+
## Backers
|
|
56
|
+
|
|
57
|
+
- Work in progress
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
ExpressoTS is **[MIT licensed](LICENSE.md)**
|
|
@@ -21,7 +21,6 @@ var BaseController_1;
|
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.BaseController = void 0;
|
|
23
23
|
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
24
|
-
const error_1 = require("../error");
|
|
25
24
|
/**
|
|
26
25
|
* The BaseController class is an abstract base class for controllers.
|
|
27
26
|
* It provides methods for handling use case calls and sending appropriate responses.
|
|
@@ -43,14 +42,7 @@ let BaseController = BaseController_1 = class BaseController {
|
|
|
43
42
|
*/
|
|
44
43
|
callUseCaseAsync(useCase, res, successStatusCode) {
|
|
45
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
dataReturn = yield useCase;
|
|
49
|
-
return res.status(successStatusCode).json(dataReturn);
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
error_1.Report.Error(error);
|
|
53
|
-
}
|
|
45
|
+
return res.status(successStatusCode).json(yield useCase);
|
|
54
46
|
});
|
|
55
47
|
}
|
|
56
48
|
/**
|
|
@@ -60,14 +52,7 @@ let BaseController = BaseController_1 = class BaseController {
|
|
|
60
52
|
* @param successStatusCode - The HTTP status code to return upon successful execution.
|
|
61
53
|
*/
|
|
62
54
|
callUseCase(useCase, res, successStatusCode) {
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
dataReturn = useCase;
|
|
66
|
-
return res.status(successStatusCode).json(dataReturn);
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
error_1.Report.Error(error);
|
|
70
|
-
}
|
|
55
|
+
return res.status(successStatusCode).json(useCase);
|
|
71
56
|
}
|
|
72
57
|
};
|
|
73
58
|
BaseController = BaseController_1 = __decorate([
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const status_code_1 = require("./status-code");
|
|
4
|
-
const logger_1 = require("../logger");
|
|
5
4
|
/**
|
|
6
5
|
* errorHandler is a custom Express error-handling middleware function.
|
|
7
6
|
* It logs the error, sets the status code, and sends a JSON response containing the status code and error message.
|
|
8
|
-
* @param error - An instance of
|
|
7
|
+
* @param error - An instance of IAppError containing error details.
|
|
9
8
|
* @param req - The Express request object.
|
|
10
9
|
* @param res - The Express response object.
|
|
11
10
|
* @param next - The Express next function for passing control to the next middleware function.
|
|
12
11
|
*/
|
|
13
12
|
function errorHandler(error, req, res, next) {
|
|
14
|
-
(0, logger_1.log)(logger_1.LogLevel.Error, error, error.service || "service-undefined");
|
|
15
13
|
res.status(error.statusCode || status_code_1.StatusCode.InternalServerError).json({ statusCode: error.statusCode, error: error.message });
|
|
16
14
|
}
|
|
17
15
|
exports.default = errorHandler;
|
package/lib/cjs/error/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Report = exports.
|
|
3
|
+
exports.Report = exports.StatusCode = void 0;
|
|
4
4
|
var status_code_1 = require("./status-code");
|
|
5
5
|
Object.defineProperty(exports, "StatusCode", { enumerable: true, get: function () { return status_code_1.StatusCode; } });
|
|
6
|
-
var application_error_1 = require("./application-error");
|
|
7
|
-
Object.defineProperty(exports, "AppError", { enumerable: true, get: function () { return application_error_1.AppError; } });
|
|
8
6
|
var report_1 = require("./report");
|
|
9
7
|
Object.defineProperty(exports, "Report", { enumerable: true, get: function () { return report_1.Report; } });
|
package/lib/cjs/error/report.js
CHANGED
|
@@ -9,16 +9,50 @@ var Report_1;
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.Report = void 0;
|
|
11
11
|
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
12
|
+
const logger_1 = require("../logger");
|
|
12
13
|
/**
|
|
13
|
-
* Report class is a utility class to manage and
|
|
14
|
+
* Report class is a utility class to manage and log errors within the application.
|
|
15
|
+
* It is responsible for creating a standardized error object, logging it,
|
|
16
|
+
* and then throwing the error for further handling.
|
|
14
17
|
*/
|
|
15
18
|
let Report = Report_1 = class Report {
|
|
16
19
|
/**
|
|
17
|
-
* Error method
|
|
18
|
-
*
|
|
20
|
+
* The Error method is responsible for generating a standardized error object,
|
|
21
|
+
* logging the error, and then throwing it for further handling.
|
|
22
|
+
* The error thrown is of the custom type IAppError, which extends the built-in Error class.
|
|
23
|
+
*
|
|
24
|
+
* @param error - An instance of Error or a string that describes the error.
|
|
25
|
+
* @param statusCode - The HTTP status code associated with the error (default is 500).
|
|
26
|
+
* @param service - The service name associated with the error. If not specified,
|
|
27
|
+
* it defaults to the name of the calling function.
|
|
28
|
+
*
|
|
29
|
+
* @throws An object of the custom type IAppError, which includes details about the error.
|
|
19
30
|
*/
|
|
20
|
-
static Error(error) {
|
|
21
|
-
|
|
31
|
+
static Error(error, statusCode, service) {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
let appError = {};
|
|
34
|
+
Error.captureStackTrace(this, this.Error);
|
|
35
|
+
const callerName = (_b = (_a = this.stack.split("\n")[1]) === null || _a === void 0 ? void 0 : _a.trim()) === null || _b === void 0 ? void 0 : _b.split(" ")[1];
|
|
36
|
+
if (error instanceof Error) {
|
|
37
|
+
appError = {
|
|
38
|
+
statusCode: statusCode !== null && statusCode !== void 0 ? statusCode : 500,
|
|
39
|
+
message: error.message,
|
|
40
|
+
service: service !== null && service !== void 0 ? service : callerName,
|
|
41
|
+
name: error.name,
|
|
42
|
+
stack: error.stack
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
appError = {
|
|
47
|
+
statusCode: statusCode !== null && statusCode !== void 0 ? statusCode : 500,
|
|
48
|
+
message: error,
|
|
49
|
+
service: service !== null && service !== void 0 ? service : callerName,
|
|
50
|
+
name: this.Error.name,
|
|
51
|
+
stack: this.stack
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
(0, logger_1.log)(logger_1.LogLevel.Error, appError, appError.service || "service-undefined");
|
|
55
|
+
throw appError;
|
|
22
56
|
}
|
|
23
57
|
};
|
|
24
58
|
Report = Report_1 = __decorate([
|
|
@@ -40,8 +40,8 @@ let GeneralLogger = GeneralLogger_1 = class GeneralLogger {
|
|
|
40
40
|
*/
|
|
41
41
|
createConsoleTransport() {
|
|
42
42
|
const consoleTransport = new winston_1.transports.Console({
|
|
43
|
-
level: "debug",
|
|
44
|
-
handleExceptions:
|
|
43
|
+
level: (process.env.ENVIRONMENT !== "Development" && "debug") || "debug",
|
|
44
|
+
handleExceptions: false,
|
|
45
45
|
handleRejections: true
|
|
46
46
|
});
|
|
47
47
|
return consoleTransport;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-controller.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/controller/base-controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"base-controller.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/controller/base-controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;;;GAIG;AACH,uBACe,cAAe,YAAW,UAAU,CAAC,UAAU;IAE1D,OAAO,CAAC,WAAW,CAAS;IAE5B;;;OAGG;gBACS,WAAW,GAAE,MAAW;IAIpC;;;;;OAKG;cACa,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM;IAI3F;;;;;OAKG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM;CAG1E;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from "express";
|
|
2
|
-
import {
|
|
2
|
+
import { IAppError } from "./report";
|
|
3
3
|
/**
|
|
4
4
|
* errorHandler is a custom Express error-handling middleware function.
|
|
5
5
|
* It logs the error, sets the status code, and sends a JSON response containing the status code and error message.
|
|
6
|
-
* @param error - An instance of
|
|
6
|
+
* @param error - An instance of IAppError containing error details.
|
|
7
7
|
* @param req - The Express request object.
|
|
8
8
|
* @param res - The Express response object.
|
|
9
9
|
* @param next - The Express next function for passing control to the next middleware function.
|
|
10
10
|
*/
|
|
11
|
-
declare function errorHandler(error:
|
|
11
|
+
declare function errorHandler(error: IAppError, req: Request, res: Response, next: NextFunction): void;
|
|
12
12
|
export default errorHandler;
|
|
13
13
|
//# sourceMappingURL=error-handler-middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler-middleware.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/error-handler-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"error-handler-middleware.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/error-handler-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC;;;;;;;GAOG;AACH,iBAAS,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAE7F;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
interface IAppError {
|
|
2
|
+
statusCode: number;
|
|
3
|
+
message: string;
|
|
4
|
+
service?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
stack?: string;
|
|
7
|
+
}
|
|
2
8
|
/**
|
|
3
|
-
* Report class is a utility class to manage and
|
|
9
|
+
* Report class is a utility class to manage and log errors within the application.
|
|
10
|
+
* It is responsible for creating a standardized error object, logging it,
|
|
11
|
+
* and then throwing the error for further handling.
|
|
4
12
|
*/
|
|
5
13
|
declare class Report {
|
|
14
|
+
static stack: string;
|
|
6
15
|
/**
|
|
7
|
-
* Error method
|
|
8
|
-
*
|
|
16
|
+
* The Error method is responsible for generating a standardized error object,
|
|
17
|
+
* logging the error, and then throwing it for further handling.
|
|
18
|
+
* The error thrown is of the custom type IAppError, which extends the built-in Error class.
|
|
19
|
+
*
|
|
20
|
+
* @param error - An instance of Error or a string that describes the error.
|
|
21
|
+
* @param statusCode - The HTTP status code associated with the error (default is 500).
|
|
22
|
+
* @param service - The service name associated with the error. If not specified,
|
|
23
|
+
* it defaults to the name of the calling function.
|
|
24
|
+
*
|
|
25
|
+
* @throws An object of the custom type IAppError, which includes details about the error.
|
|
9
26
|
*/
|
|
10
|
-
static Error(error:
|
|
27
|
+
static Error(error: Error | string, statusCode?: number, service?: string): void;
|
|
11
28
|
}
|
|
12
|
-
export { Report };
|
|
29
|
+
export { Report, IAppError };
|
|
13
30
|
//# sourceMappingURL=report.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/report.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/report.ts"],"names":[],"mappings":"AAGA,UAAU,SAAS;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,cACM,MAAM;IACR,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC;IAErB;;;;;;;;;;;OAWG;WACW,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;CA6B1F;AAED,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -9,7 +9,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
var BaseController_1;
|
|
11
11
|
import { provide } from 'inversify-binding-decorators';
|
|
12
|
-
import { Report } from '../error';
|
|
13
12
|
/**
|
|
14
13
|
* The BaseController class is an abstract base class for controllers.
|
|
15
14
|
* It provides methods for handling use case calls and sending appropriate responses.
|
|
@@ -31,14 +30,7 @@ let BaseController = BaseController_1 = class BaseController {
|
|
|
31
30
|
* @param successStatusCode - The HTTP status code to return upon successful execution.
|
|
32
31
|
*/
|
|
33
32
|
async callUseCaseAsync(useCase, res, successStatusCode) {
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
dataReturn = await useCase;
|
|
37
|
-
return res.status(successStatusCode).json(dataReturn);
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
Report.Error(error);
|
|
41
|
-
}
|
|
33
|
+
return res.status(successStatusCode).json(await useCase);
|
|
42
34
|
}
|
|
43
35
|
/**
|
|
44
36
|
* Calls a use case and sends an appropriate response based on the result.
|
|
@@ -47,14 +39,7 @@ let BaseController = BaseController_1 = class BaseController {
|
|
|
47
39
|
* @param successStatusCode - The HTTP status code to return upon successful execution.
|
|
48
40
|
*/
|
|
49
41
|
callUseCase(useCase, res, successStatusCode) {
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
dataReturn = useCase;
|
|
53
|
-
return res.status(successStatusCode).json(dataReturn);
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
Report.Error(error);
|
|
57
|
-
}
|
|
42
|
+
return res.status(successStatusCode).json(useCase);
|
|
58
43
|
}
|
|
59
44
|
};
|
|
60
45
|
BaseController = BaseController_1 = __decorate([
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { StatusCode } from "./status-code";
|
|
2
|
-
import { LogLevel, log } from "../logger";
|
|
3
2
|
/**
|
|
4
3
|
* errorHandler is a custom Express error-handling middleware function.
|
|
5
4
|
* It logs the error, sets the status code, and sends a JSON response containing the status code and error message.
|
|
6
|
-
* @param error - An instance of
|
|
5
|
+
* @param error - An instance of IAppError containing error details.
|
|
7
6
|
* @param req - The Express request object.
|
|
8
7
|
* @param res - The Express response object.
|
|
9
8
|
* @param next - The Express next function for passing control to the next middleware function.
|
|
10
9
|
*/
|
|
11
10
|
function errorHandler(error, req, res, next) {
|
|
12
|
-
log(LogLevel.Error, error, error.service || "service-undefined");
|
|
13
11
|
res.status(error.statusCode || StatusCode.InternalServerError).json({ statusCode: error.statusCode, error: error.message });
|
|
14
12
|
}
|
|
15
13
|
export default errorHandler;
|
package/lib/esm/error/index.js
CHANGED
package/lib/esm/error/report.js
CHANGED
|
@@ -6,16 +6,50 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
var Report_1;
|
|
8
8
|
import { provide } from "inversify-binding-decorators";
|
|
9
|
+
import { LogLevel, log } from '../logger';
|
|
9
10
|
/**
|
|
10
|
-
* Report class is a utility class to manage and
|
|
11
|
+
* Report class is a utility class to manage and log errors within the application.
|
|
12
|
+
* It is responsible for creating a standardized error object, logging it,
|
|
13
|
+
* and then throwing the error for further handling.
|
|
11
14
|
*/
|
|
12
15
|
let Report = Report_1 = class Report {
|
|
16
|
+
static stack;
|
|
13
17
|
/**
|
|
14
|
-
* Error method
|
|
15
|
-
*
|
|
18
|
+
* The Error method is responsible for generating a standardized error object,
|
|
19
|
+
* logging the error, and then throwing it for further handling.
|
|
20
|
+
* The error thrown is of the custom type IAppError, which extends the built-in Error class.
|
|
21
|
+
*
|
|
22
|
+
* @param error - An instance of Error or a string that describes the error.
|
|
23
|
+
* @param statusCode - The HTTP status code associated with the error (default is 500).
|
|
24
|
+
* @param service - The service name associated with the error. If not specified,
|
|
25
|
+
* it defaults to the name of the calling function.
|
|
26
|
+
*
|
|
27
|
+
* @throws An object of the custom type IAppError, which includes details about the error.
|
|
16
28
|
*/
|
|
17
|
-
static Error(error) {
|
|
18
|
-
|
|
29
|
+
static Error(error, statusCode, service) {
|
|
30
|
+
let appError = {};
|
|
31
|
+
Error.captureStackTrace(this, this.Error);
|
|
32
|
+
const callerName = this.stack.split("\n")[1]?.trim()?.split(" ")[1];
|
|
33
|
+
if (error instanceof Error) {
|
|
34
|
+
appError = {
|
|
35
|
+
statusCode: statusCode ?? 500,
|
|
36
|
+
message: error.message,
|
|
37
|
+
service: service ?? callerName,
|
|
38
|
+
name: error.name,
|
|
39
|
+
stack: error.stack
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
appError = {
|
|
44
|
+
statusCode: statusCode ?? 500,
|
|
45
|
+
message: error,
|
|
46
|
+
service: service ?? callerName,
|
|
47
|
+
name: this.Error.name,
|
|
48
|
+
stack: this.stack
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
log(LogLevel.Error, appError, appError.service || "service-undefined");
|
|
52
|
+
throw appError;
|
|
19
53
|
}
|
|
20
54
|
};
|
|
21
55
|
Report = Report_1 = __decorate([
|
|
@@ -34,8 +34,8 @@ let GeneralLogger = GeneralLogger_1 = class GeneralLogger {
|
|
|
34
34
|
*/
|
|
35
35
|
createConsoleTransport() {
|
|
36
36
|
const consoleTransport = new transports.Console({
|
|
37
|
-
level: "debug",
|
|
38
|
-
handleExceptions:
|
|
37
|
+
level: (process.env.ENVIRONMENT !== "Development" && "debug") || "debug",
|
|
38
|
+
handleExceptions: false,
|
|
39
39
|
handleRejections: true
|
|
40
40
|
});
|
|
41
41
|
return consoleTransport;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-controller.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/controller/base-controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"base-controller.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/controller/base-controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;;;GAIG;AACH,uBACe,cAAe,YAAW,UAAU,CAAC,UAAU;IAE1D,OAAO,CAAC,WAAW,CAAS;IAE5B;;;OAGG;gBACS,WAAW,GAAE,MAAW;IAIpC;;;;;OAKG;cACa,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM;IAI3F;;;;;OAKG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM;CAG1E;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from "express";
|
|
2
|
-
import {
|
|
2
|
+
import { IAppError } from "./report";
|
|
3
3
|
/**
|
|
4
4
|
* errorHandler is a custom Express error-handling middleware function.
|
|
5
5
|
* It logs the error, sets the status code, and sends a JSON response containing the status code and error message.
|
|
6
|
-
* @param error - An instance of
|
|
6
|
+
* @param error - An instance of IAppError containing error details.
|
|
7
7
|
* @param req - The Express request object.
|
|
8
8
|
* @param res - The Express response object.
|
|
9
9
|
* @param next - The Express next function for passing control to the next middleware function.
|
|
10
10
|
*/
|
|
11
|
-
declare function errorHandler(error:
|
|
11
|
+
declare function errorHandler(error: IAppError, req: Request, res: Response, next: NextFunction): void;
|
|
12
12
|
export default errorHandler;
|
|
13
13
|
//# sourceMappingURL=error-handler-middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler-middleware.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/error-handler-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"error-handler-middleware.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/error-handler-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC;;;;;;;GAOG;AACH,iBAAS,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAE7F;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
interface IAppError {
|
|
2
|
+
statusCode: number;
|
|
3
|
+
message: string;
|
|
4
|
+
service?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
stack?: string;
|
|
7
|
+
}
|
|
2
8
|
/**
|
|
3
|
-
* Report class is a utility class to manage and
|
|
9
|
+
* Report class is a utility class to manage and log errors within the application.
|
|
10
|
+
* It is responsible for creating a standardized error object, logging it,
|
|
11
|
+
* and then throwing the error for further handling.
|
|
4
12
|
*/
|
|
5
13
|
declare class Report {
|
|
14
|
+
static stack: string;
|
|
6
15
|
/**
|
|
7
|
-
* Error method
|
|
8
|
-
*
|
|
16
|
+
* The Error method is responsible for generating a standardized error object,
|
|
17
|
+
* logging the error, and then throwing it for further handling.
|
|
18
|
+
* The error thrown is of the custom type IAppError, which extends the built-in Error class.
|
|
19
|
+
*
|
|
20
|
+
* @param error - An instance of Error or a string that describes the error.
|
|
21
|
+
* @param statusCode - The HTTP status code associated with the error (default is 500).
|
|
22
|
+
* @param service - The service name associated with the error. If not specified,
|
|
23
|
+
* it defaults to the name of the calling function.
|
|
24
|
+
*
|
|
25
|
+
* @throws An object of the custom type IAppError, which includes details about the error.
|
|
9
26
|
*/
|
|
10
|
-
static Error(error:
|
|
27
|
+
static Error(error: Error | string, statusCode?: number, service?: string): void;
|
|
11
28
|
}
|
|
12
|
-
export { Report };
|
|
29
|
+
export { Report, IAppError };
|
|
13
30
|
//# sourceMappingURL=report.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/report.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/report.ts"],"names":[],"mappings":"AAGA,UAAU,SAAS;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,cACM,MAAM;IACR,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC;IAErB;;;;;;;;;;;OAWG;WACW,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;CA6B1F;AAED,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC"}
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/core",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"win-clean": "if exist lib (del /q lib\\*)",
|
|
54
|
-
"linux-clean": "rm -
|
|
54
|
+
"linux-clean": "rm -rf lib/*",
|
|
55
55
|
"win-cpy": "xcopy package.json lib\\ && xcopy README.md lib\\ && xcopy CHANGELOG.md lib\\ /Y",
|
|
56
56
|
"linux-cpy": "cp package.json README.md CHANGELOG.md lib/",
|
|
57
57
|
"build:win": "npm run win-clean && npm run build:esm && npm run build:cjs && npm run win-cpy",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/core",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"win-clean": "if exist lib (del /q lib\\*)",
|
|
54
|
-
"linux-clean": "rm -
|
|
54
|
+
"linux-clean": "rm -rf lib/*",
|
|
55
55
|
"win-cpy": "xcopy package.json lib\\ && xcopy README.md lib\\ && xcopy CHANGELOG.md lib\\ /Y",
|
|
56
56
|
"linux-cpy": "cp package.json README.md CHANGELOG.md lib/",
|
|
57
57
|
"build:win": "npm run win-clean && npm run build:esm && npm run build:cjs && npm run win-cpy",
|