Skip to content

Commit

Permalink
fix: retry request for '"system:anonymous" cannot get resource' error
Browse files Browse the repository at this point in the history
Signed-off-by: David Kwon <dakwon@redhat.com>
  • Loading branch information
dkwon17 committed Oct 17, 2023
1 parent f799e06 commit ca96c5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type AxiosFunc = (url: string, config?: AxiosRequestConfig) => Promise<any>;
type AxiosFuncWithData = (url: string, data?: any, config?: AxiosRequestConfig) => Promise<any>;

export const bearerTokenAuthorizationIsRequiredErrorMsg = 'Bearer Token Authorization is required';
export const cannotGetResourceErrorMessage =
'users.user.openshift.io "~" is forbidden: User "system:anonymous" cannot get resource "users" in API group "user.openshift.io" at the cluster scope';

export class AxiosWrapper {
protected readonly retryCount = 3;
Expand All @@ -34,6 +36,10 @@ export class AxiosWrapper {
return new AxiosWrapper(axios.create(), bearerTokenAuthorizationIsRequiredErrorMsg);
}

static createToRetryCannotGetResourceErrors(): AxiosWrapper {
return new AxiosWrapper(axios.create(), cannotGetResourceErrorMessage);
}

static createToRetryAnyErrors(): AxiosWrapper {
return new AxiosWrapper(axios.create());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export async function getKubernetesNamespace(): Promise<che.KubernetesNamespace[
}

export async function provisionKubernetesNamespace(): Promise<che.KubernetesNamespace> {
const response = await axios.post(`${cheServerPrefix}/kubernetes/namespace/provision`);
const response = await AxiosWrapper.createToRetryCannotGetResourceErrors().post(
`${cheServerPrefix}/kubernetes/namespace/provision`,
);

return response.data;
}

0 comments on commit ca96c5f

Please sign in to comment.