Skip to content

Commit

Permalink
Internal server error on erros from formio when getting user
Browse files Browse the repository at this point in the history
  • Loading branch information
lotorvik committed Jun 13, 2024
1 parent 602d0a2 commit 24dd089
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HttpError } from '../../../fetchUtils';
import { formioService } from '../../../services';
import { ByggerRequest } from '../../../types';
import { getFormioToken } from '../../../util/requestTool';
import { BadRequest, UnauthorizedError } from './errors';
import { InternalServerError, UnauthorizedError } from './errors';

const authorizedPublisher = async (req: ByggerRequest, res: Response, next: NextFunction) => {
const formioToken = getFormioToken(req);
Expand All @@ -17,7 +17,7 @@ const authorizedPublisher = async (req: ByggerRequest, res: Response, next: Next
if ((e as HttpError).response?.status === 401) {
next(new UnauthorizedError('Invalid formio token'));
} else {
next(new BadRequest('Could not fetch user'));
next(new InternalServerError('Could not fetch user'));
}
return;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/bygger-backend/src/routers/api/helpers/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export class BadRequest extends HttpError {
}
}

export class InternalServerError extends HttpError {
constructor(message: string) {
super(message, 500);
}
}

export class ApiError extends Error {
cause?: Error;
functional: boolean;
Expand Down

0 comments on commit 24dd089

Please sign in to comment.