express-sweet-generator 2.0.6 → 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.
@@ -2,7 +2,7 @@ const express = require('express');
2
2
  const expressExtension = require('express-sweet');
3
3
  const {query, body, validationResult} = require('express-validator');
4
4
  const UserModel = require('../../models/UserModel');
5
- const UserNotFound = require('../../exceptions/UserNotFound');
5
+ const NotFoundError = require('../../errors/NotFoundError');
6
6
  const CustomValidation = require('../../shared/CustomValidation');
7
7
 
8
8
  const router = express.Router();
@@ -81,7 +81,7 @@ router.put('/:userId(\\d+)', [
81
81
  await UserModel.updateUser(req.params.userId, req.body.user);
82
82
  res.json(true);
83
83
  } catch (error) {
84
- if (error instanceof UserNotFound)
84
+ if (error instanceof NotFoundError)
85
85
  res.json({error: error.name});
86
86
  else
87
87
  next(error);
@@ -106,7 +106,7 @@ router.put('/profile', [
106
106
  await UserModel.updateUser(req.user.id, req.body.user);
107
107
  res.json(true);
108
108
  } catch (error) {
109
- if (error instanceof UserNotFound)
109
+ if (error instanceof NotFoundError)
110
110
  res.json({error: error.name});
111
111
  else
112
112
  next(error);
@@ -50,7 +50,7 @@ function initForm() {
50
50
  const {data} = await userApi.updateProfile(new FormData(validation.form));
51
51
  validation.offIndicator();
52
52
  if (data.error)
53
- if (data.error === 'UserNotFound') {
53
+ if (data.error === 'NotFoundError') {
54
54
  await components.Dialog.warning('The account you are using has been deleted and you will be forcibly logged out.');
55
55
  return void userApi.logout();
56
56
  } else
@@ -269,7 +269,7 @@ export default class extends components.Modal {
269
269
  // User update request.
270
270
  const {data} = await this.#userApi.updateUser(this.#userId, new FormData(this.#validator.form));
271
271
  this.#validator.offIndicator();
272
- if (data?.error === 'UserNotFound') {
272
+ if (data?.error === 'NotFoundError') {
273
273
  await components.Dialog.warning('This user has been deleted.');
274
274
  return void super.hide(true);
275
275
  }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Custom error class for "Not Found" errors.
3
+ */
4
+ export default 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
  import * as expressExtension from 'express-sweet';
2
2
  import {Media} from 'nodejs-shared';
3
- import UserNotFound from '../exceptions/UserNotFound.js';
3
+ import NotFoundError from '../errors/NotFoundError.js';
4
4
  import ProfileModel from './ProfileModel.js';
5
5
  import CommentModel from './CommentModel.js';
6
6
  import BookModel from './BookModel.js';
@@ -123,7 +123,7 @@ export default 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;