Skip to content

Commit

Permalink
fix: replace assert with error (#3074)
Browse files Browse the repository at this point in the history
This PR changes the behavior of checking the incoming token on the
`/api/frontend` path. Instead of using assert resulting in a 500 error
we are throwing an error that is caught by the default controller and
emitted back to the user as JSON.

This should be the correct behaviour, since the endpoint can not give
you any meaningful data without the environment that the API token
holds.
  • Loading branch information
FredrikOseberg committed Feb 13, 2023
1 parent 346537b commit 9cc7b8f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/lib/services/proxy-service.ts
Expand Up @@ -15,8 +15,7 @@ import {
frontendSettingsKey,
} from '../types/settings/frontend-settings';
import { validateOrigins } from '../util';
import { BadDataError } from '../error';
import assert from 'assert';
import { BadDataError, InvalidTokenError } from '../error';
import { minutesToMilliseconds } from 'date-fns';

type Config = Pick<
Expand Down Expand Up @@ -159,7 +158,9 @@ export class ProxyService {
}

private static assertExpectedTokenType({ type }: ApiUser) {
assert(type === ApiTokenType.FRONTEND || type === ApiTokenType.ADMIN);
if (!(type === ApiTokenType.FRONTEND || type === ApiTokenType.ADMIN)) {
throw new InvalidTokenError();
}
}

async setFrontendSettings(
Expand Down

0 comments on commit 9cc7b8f

Please sign in to comment.