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:
parent
346537bae9
commit
9cc7b8fdeb
@ -15,8 +15,7 @@ import {
|
|||||||
frontendSettingsKey,
|
frontendSettingsKey,
|
||||||
} from '../types/settings/frontend-settings';
|
} from '../types/settings/frontend-settings';
|
||||||
import { validateOrigins } from '../util';
|
import { validateOrigins } from '../util';
|
||||||
import { BadDataError } from '../error';
|
import { BadDataError, InvalidTokenError } from '../error';
|
||||||
import assert from 'assert';
|
|
||||||
import { minutesToMilliseconds } from 'date-fns';
|
import { minutesToMilliseconds } from 'date-fns';
|
||||||
|
|
||||||
type Config = Pick<
|
type Config = Pick<
|
||||||
@ -159,7 +158,9 @@ export class ProxyService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static assertExpectedTokenType({ type }: ApiUser) {
|
private static assertExpectedTokenType({ type }: ApiUser) {
|
||||||
assert(type === ApiTokenType.FRONTEND || type === ApiTokenType.ADMIN);
|
if (!(type === ApiTokenType.FRONTEND || type === ApiTokenType.ADMIN)) {
|
||||||
|
throw new InvalidTokenError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async setFrontendSettings(
|
async setFrontendSettings(
|
||||||
|
Loading…
Reference in New Issue
Block a user