mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 15:31:19 +00:00
refactor: Prefer use of RequestError and next() function on middlewares
Added: - New error types such as `IntegrationNotFoundError`, `WorkspaceNotFoundError`, `AccountNotFoundError' and more. Refactored: - Refactored most of the middlewares and very little number of helper functions to use RequestError - Deleted unused imports Changed: - Some of the error types in middlewares changed to more related error types. - Environment variable of 'VERBOSE_ERROR_OUTPUT' changed to more reliable validation method in `config/index.ts` as per @dangtony98 requested.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { ServiceToken } from '../models';
|
||||
import { JWT_SERVICE_SECRET } from '../config';
|
||||
import { BadRequestError, UnauthorizedRequestError } from '../utils/errors';
|
||||
@@ -42,7 +41,7 @@ const requireServiceTokenAuth = async (
|
||||
.populate('user', '+publicKey')
|
||||
.select('+encryptedKey +publicKey +nonce');
|
||||
|
||||
if (!serviceToken) return next(UnauthorizedRequestError({message: 'Failed to locate Service Token'}))
|
||||
if (!serviceToken) return next(UnauthorizedRequestError({message: 'The service token does not match the record in the database'}))
|
||||
|
||||
req.serviceToken = serviceToken;
|
||||
return next();
|
||||
|
||||
Reference in New Issue
Block a user