speedly 2.0.37 → 2.0.38

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.
@@ -7,6 +7,7 @@ exports.default = speedly;
7
7
  const express_1 = __importDefault(require("express"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
+ const util_1 = require("../util");
10
11
  const document_1 = __importDefault(require("../document"));
11
12
  const defaultConfig = {
12
13
  notFoundHandler: true,
@@ -59,9 +60,23 @@ function speedly(config = {}) {
59
60
  app.use((req, res) => res.status(404).json({ message: "Not Found" }));
60
61
  }
61
62
  if (finalConfig.errorHandler) {
62
- app.use((error, req, res, next) => {
63
- console.error("Speedly Error:", error);
64
- res.status(500).json({ message: "Internal Server Error" });
63
+ app.use(async (err, req, res, _next) => {
64
+ console.log("app", 39, err);
65
+ const config = { translate: true, ...(err.config || {}) };
66
+ const body = err.json || {
67
+ message: err.message || "internal error",
68
+ };
69
+ if (err?.status == 401)
70
+ return res.status(err.status).json(body);
71
+ if (body.message && req.query.lang !== "en" && config.translate)
72
+ try {
73
+ body.message = await (0, util_1.translator)(body.message, (typeof req.query.lang === "string" ? req.query.lang : "fa") ||
74
+ "fa");
75
+ }
76
+ catch (error) {
77
+ console.error("Translation error:", error);
78
+ }
79
+ res.status(err.status || 500).json(body);
65
80
  });
66
81
  }
67
82
  };
@@ -247,7 +247,7 @@ function RouterFetcher(baseDir, servers) {
247
247
  return {
248
248
  openapi: "3.0.3",
249
249
  info: {
250
- title: `${require(path_1.default.join(process.cwd(), "package.json")).name} APIs`,
250
+ title: `${require(path_1.default.join(process.cwd(), "package.json")).name} Documentation`,
251
251
  version: "1.0.0",
252
252
  },
253
253
  servers,
@@ -7,6 +7,7 @@ exports.default = speedly;
7
7
  const express_1 = __importDefault(require("express"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
+ const util_1 = require("../util");
10
11
  const document_1 = __importDefault(require("../document"));
11
12
  const defaultConfig = {
12
13
  notFoundHandler: true,
@@ -59,9 +60,23 @@ function speedly(config = {}) {
59
60
  app.use((req, res) => res.status(404).json({ message: "Not Found" }));
60
61
  }
61
62
  if (finalConfig.errorHandler) {
62
- app.use((error, req, res, next) => {
63
- console.error("Speedly Error:", error);
64
- res.status(500).json({ message: "Internal Server Error" });
63
+ app.use(async (err, req, res, _next) => {
64
+ console.log("app", 39, err);
65
+ const config = { translate: true, ...(err.config || {}) };
66
+ const body = err.json || {
67
+ message: err.message || "internal error",
68
+ };
69
+ if (err?.status == 401)
70
+ return res.status(err.status).json(body);
71
+ if (body.message && req.query.lang !== "en" && config.translate)
72
+ try {
73
+ body.message = await (0, util_1.translator)(body.message, (typeof req.query.lang === "string" ? req.query.lang : "fa") ||
74
+ "fa");
75
+ }
76
+ catch (error) {
77
+ console.error("Translation error:", error);
78
+ }
79
+ res.status(err.status || 500).json(body);
65
80
  });
66
81
  }
67
82
  };
@@ -247,7 +247,7 @@ function RouterFetcher(baseDir, servers) {
247
247
  return {
248
248
  openapi: "3.0.3",
249
249
  info: {
250
- title: `${require(path_1.default.join(process.cwd(), "package.json")).name} APIs`,
250
+ title: `${require(path_1.default.join(process.cwd(), "package.json")).name} Documentation`,
251
251
  version: "1.0.0",
252
252
  },
253
253
  servers,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speedly",
3
- "version": "2.0.37",
3
+ "version": "2.0.38",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",