Skip to content

Commit

Permalink
Do not log out if not 401
Browse files Browse the repository at this point in the history
  • Loading branch information
lotorvik committed Jun 12, 2024
1 parent 4acdb79 commit 40b1aab
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NextFunction, Response } from 'express';
import { formioService } from '../../../services';
import { ByggerRequest } from '../../../types';
import { getFormioToken } from '../../../util/requestTool';
import { UnauthorizedError } from './errors';
import { BadRequest, HttpError, UnauthorizedError } from './errors';

const authorizedPublisher = async (req: ByggerRequest, res: Response, next: NextFunction) => {
const formioToken = getFormioToken(req);
Expand All @@ -13,7 +13,11 @@ const authorizedPublisher = async (req: ByggerRequest, res: Response, next: Next
try {
await formioService.getFormioUser(formioToken);
} catch (e) {
next(new UnauthorizedError('Invalid formio token'));
if ((e as HttpError).status === 401) {
next(new UnauthorizedError('Invalid formio token'));
} else {
next(new BadRequest('Could not fetch user'));
}
return;
}
req.getFormioToken = () => formioToken;
Expand Down

0 comments on commit 40b1aab

Please sign in to comment.