1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

fix: replace assert with error (#3074)

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.
This commit is contained in:
Fredrik Strand Oseberg 2023-02-13 08:40:04 +01:00 committed by GitHub
parent 346537bae9
commit 9cc7b8fdeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<
@ -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(