fix: handle access result gracefully
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Forbidden } from '../errors';
|
||||
import { Access } from '../config/types';
|
||||
import { Access, AccessResult } from '../config/types';
|
||||
|
||||
const executeAccess = async (operation, access: Access): Promise<boolean> => {
|
||||
const executeAccess = async (operation, access: Access): Promise<AccessResult> => {
|
||||
if (access) {
|
||||
const result = await access(operation);
|
||||
|
||||
|
||||
@@ -49,7 +49,8 @@ export type MockEmailCredentials = {
|
||||
web: string;
|
||||
};
|
||||
|
||||
export type Access = (args?: any) => boolean | Where;
|
||||
export type AccessResult = boolean | Where;
|
||||
export type Access = (args?: any) => AccessResult;
|
||||
|
||||
export type PayloadConfig = {
|
||||
admin?: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import httpStatus from 'http-status';
|
||||
import { Response } from 'express';
|
||||
import { NextFunction, Response } from 'express';
|
||||
import { Logger } from 'pino';
|
||||
import { Config } from '../../config/types';
|
||||
import formatErrorResponse, { ErrorResponse } from '../responses/formatError';
|
||||
@@ -10,7 +10,7 @@ export type ErrorHandler = (err: Error, req: PayloadRequest, res: Response) => P
|
||||
|
||||
// NextFunction must be passed for Express to use this middleware as error handler
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const errorHandler = (config: Config, logger: Logger) => async (err: APIError, req: PayloadRequest, res: Response): Promise<void> => {
|
||||
const errorHandler = (config: Config, logger: Logger) => async (err: APIError, req: PayloadRequest, res: Response, next: NextFunction): Promise<void> => {
|
||||
let response = formatErrorResponse(err);
|
||||
let status = err.status || httpStatus.INTERNAL_SERVER_ERROR;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user