express-sweet-generator 2.0.5 → 2.0.7

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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  A comprehensive list of changes in each version may be found in the [CHANGELOG](CHANGELOG.md).
5
5
 
6
6
  ## Installation
7
- ```sh
7
+ ```bash
8
8
  npm install -g express-sweet-generator
9
9
  ```
10
10
 
@@ -14,11 +14,11 @@ Use the application generator tool, `express-sweet-generator`, to quickly create
14
14
  ![Image](screencaps/demonstration.webp)
15
15
 
16
16
  1. For example, the following creates an Express app named `myapp`. The app will be created in a folder named `myapp` in the current working directory.
17
- ```sh
17
+ ```bash
18
18
  express-sweet -o esm myapp
19
19
  ```
20
20
  1. Then install dependencies.
21
- ```sh
21
+ ```bash
22
22
  cd myapp/
23
23
  npm install
24
24
  ```
@@ -116,16 +116,16 @@ Use the application generator tool, `express-sweet-generator`, to quickly create
116
116
  }
117
117
  ```
118
118
  1. The DB to be accessed can be defined for each environment. Specify the environment in the `.env` file
119
- ```sh
119
+ ```bash
120
120
  NODE_ENV=development
121
121
  ```
122
122
  1. Run the application with the following command.
123
- ```sh
123
+ ```bash
124
124
  npm start
125
125
  ```
126
126
  1. Then, load `http://localhost:3000/` in your browser to access the app.
127
127
  The generated app has the following directory structure:
128
- ```sh
128
+ ```bash
129
129
  .
130
130
  ├── .env
131
131
  ├── app.js
@@ -143,8 +143,8 @@ Use the application generator tool, `express-sweet-generator`, to quickly create
143
143
  │ ├── config.js
144
144
  │ ├── database.js
145
145
  │ └── view.js
146
- ├── exceptions
147
- │ └── UserNotFound.js
146
+ ├── errors
147
+ │ └── NotFoundError.js
148
148
  ├── models
149
149
  │ ├── BookModel.js
150
150
  │ ├── CommentModel.js
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  const ejs = require('ejs');
3
3
  const fs = require('fs-extra');
4
4
  const path = require('path');
@@ -112,9 +112,9 @@ function getAppName(installDir) {
112
112
  * @param {Function} fn
113
113
  */
114
114
  function existsInstallationDirectory(dir, fn) {
115
- fs.readdir(dir, (err, files) => {
116
- if (err && err.code !== 'ENOENT')
117
- throw err;
115
+ fs.readdir(dir, (error, files) => {
116
+ if (error && error.code !== 'ENOENT')
117
+ throw error;
118
118
  fn(!files || !files.length);
119
119
  });
120
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-sweet-generator",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "description": "EXPRESS SWEET application generator.",
5
5
  "main": "bin/express-sweet-cli.js",
6
6
  "files": [
@@ -65,11 +65,11 @@ module.exports = {
65
65
 
66
66
  /**
67
67
  * Hooks the default behavior on request errors.
68
- * If unset, simply returns an error HTTP status. (<code>res.status(err.status||500).end();</code>)
69
- * @type {(err: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
68
+ * If unset, simply returns an error HTTP status. (<code>res.status(error.status||500).end();</code>)
69
+ * @type {(error: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
70
70
  * @example
71
- * hook_handle_error: (err, req, res, next) => {
72
- * if (err.status === 404)
71
+ * hook_handle_error: (error, req, res, next) => {
72
+ * if (error.status === 404)
73
73
  * // If the URL cannot be found, a 404 error screen (views/errors/404.hbs) is displayed.
74
74
  * res.render('errors/404');
75
75
  * else
@@ -77,8 +77,8 @@ module.exports = {
77
77
  * res.render('error/500');
78
78
  * },
79
79
  */
80
- hook_handle_error: (err, req, res, next) => {
81
- if (err.status === 404)
80
+ hook_handle_error: (error, req, res, next) => {
81
+ if (error.status === 404)
82
82
  res.status(404).render('errors/404', {isErrorPage: true});
83
83
  else
84
84
  res.status(500).render('errors/500', {isErrorPage: true});
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Custom error class for "Not Found" errors.
3
+ */
4
+ module.exports = class extends Error {
5
+ /**
6
+ * Creates a new NotFoundError instance.
7
+ * @param {string} [message='The requested record could not be found.'] - The error message.
8
+ */
9
+ constructor(message = 'The requested record could not be found.') {
10
+ super(message);
11
+ this.name = 'NotFoundError';
12
+ this.statusCode = 404; // HTTP status code for "Not Found"
13
+ }
14
+ }
@@ -1,6 +1,6 @@
1
1
  const expressExtension = require('express-sweet');
2
2
  const {Media} = require('nodejs-shared');
3
- const UserNotFound = require('../exceptions/UserNotFound');
3
+ const NotFoundError = require('../errors/NotFoundError');
4
4
 
5
5
  module.exports = class extends expressExtension.database.Model {
6
6
  static get table() {
@@ -105,10 +105,10 @@ module.exports = class extends expressExtension.database.Model {
105
105
  }, {transaction});
106
106
  await this.#updateUserIcon(user, set.icon, transaction);
107
107
  await transaction.commit();
108
- } catch (err) {
108
+ } catch (error) {
109
109
  if (transaction)
110
110
  await transaction.rollback();
111
- throw err;
111
+ throw error;
112
112
  }
113
113
  }
114
114
 
@@ -123,7 +123,7 @@ module.exports = class extends expressExtension.database.Model {
123
123
  }, set);
124
124
  const user = await this.getUser(userId);
125
125
  if (!user)
126
- throw new UserNotFound();
126
+ throw new NotFoundError();
127
127
  transaction = await super.begin();
128
128
  user.email = set.email;
129
129
  user.name = set.name;
@@ -133,10 +133,10 @@ module.exports = class extends expressExtension.database.Model {
133
133
  await user.save({transaction});
134
134
  await this.#updateUserIcon(user, set.icon, transaction);
135
135
  await transaction.commit();
136
- } catch (err) {
136
+ } catch (error) {
137
137
  if (transaction)
138
138
  await transaction.rollback();
139
- throw err;
139
+ throw error;
140
140
  }
141
141
  }
142
142