Fix permissions API to return 401 instead of 500 when IdentityApi.getIdentity throws an error

Signed-off-by: huansong.tang <huansong.tang@grabtaxi.com>
This commit is contained in:
huansong.tang
2022-10-07 15:52:24 +08:00
parent 61f5da108c
commit f3a3fefb96
2 changed files with 7 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-auth-node': minor
---
Ensure `getIdentity` throws an `AuthenticationError` instead of a `NotAllowed` error when authentication fails
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import { AuthenticationError, NotAllowedError } from '@backstage/errors';
import { AuthenticationError } from '@backstage/errors';
import {
createRemoteJWKSet,
decodeJwt,
@@ -86,7 +86,7 @@ export class DefaultIdentityClient implements IdentityApi {
getBearerTokenFromAuthorizationHeader(request.headers.authorization),
);
} catch (e) {
throw new NotAllowedError(e.message);
throw new AuthenticationError(e.message);
}
}