Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not dispatch a warning, if the git provider is not supported
Browse files Browse the repository at this point in the history
vinokurig committed Jan 28, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 6c0d01f commit 7ea3c7c
Showing 4 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ import SessionStorageService, { SessionStorageKey } from '@/services/session-sto
import { RootState } from '@/store';
import { selectBranding } from '@/store/Branding';
import { factoryResolverActionCreators, selectFactoryResolver } from '@/store/FactoryResolver';
import { FACTORY_RESOLVER_NOT_FOUND_ERROR_MESSAGE } from '@/store/Workspaces/devWorkspaces/actions/actionCreators/const';
import { selectAllWorkspaces } from '@/store/Workspaces/selectors';

export class ApplyingDevfileError extends Error {
@@ -212,8 +213,7 @@ class CreatingStepFetchDevfile extends ProgressStep<Props, State> {
}
if (
errorMessage === 'Failed to fetch devfile' ||
errorMessage ===
'Cannot build factory with any of the provided parameters. Please check parameters correctness, and resend query.' ||
errorMessage === FACTORY_RESOLVER_NOT_FOUND_ERROR_MESSAGE ||
errorMessage.startsWith('Could not reach devfile')
) {
this.setState({ useDefaultDevfile: true });
Original file line number Diff line number Diff line change
@@ -201,6 +201,34 @@ describe('devWorkspaces, actions', () => {
expect(actions[2]).toEqual(devWorkspacesErrorAction(expect.any(String)));
});

it('should not dispatch a warning for unsupported provider', async () => {
const mockError = {
response: {
data: {
message: 'Invalid token',
},
},
};

(OAuthService.refreshTokenIfProjectExists as jest.Mock).mockRejectedValueOnce(mockError);
(getWarningFromResponse as jest.Mock).mockReturnValueOnce(
'Cannot build factory with any of the provided parameters. Please check parameters correctness, and resend query.',
);

// let's stop the workspace start at this point
// as we want to test the warning dispatch only
(checkRunningDevWorkspacesClusterLimitExceeded as jest.Mock).mockImplementationOnce(() => {
throw new Error('Cluster limit exceeded');
});

await expect(store.dispatch(startWorkspace(mockWorkspace))).rejects.toThrow();

const actions = store.getActions();
expect(actions).toHaveLength(2);
expect(actions[0]).toEqual(devWorkspacesRequestAction());
expect(actions[1]).toEqual(devWorkspacesErrorAction(expect.any(String)));
});

it('should dispatch update action on successful start', async () => {
await store.dispatch(startWorkspace(mockWorkspace));

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2018-2024 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

export const FACTORY_RESOLVER_NOT_FOUND_ERROR_MESSAGE =
'Cannot build factory with any of the provided parameters. Please check parameters correctness, and resend query.';
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ import {
devWorkspacesClusterActionCreators,
} from '@/store/DevWorkspacesCluster';
import { verifyAuthorized } from '@/store/SanityCheck';
import { FACTORY_RESOLVER_NOT_FOUND_ERROR_MESSAGE } from '@/store/Workspaces/devWorkspaces/actions/actionCreators/const';
import {
checkDevWorkspaceNextStartAnnotation,
checkRunningWorkspacesLimit,
@@ -61,9 +62,9 @@ export const startWorkspace =
await OAuthService.refreshTokenIfProjectExists(workspace);
} catch (e: unknown) {
// Do not interrupt the workspace start, but show a warning notification.

const warnMessage = getWarningFromResponse(e);
if (warnMessage) {
// Do not dispatch a warning, if the git provider is not supported.
if (warnMessage && warnMessage !== FACTORY_RESOLVER_NOT_FOUND_ERROR_MESSAGE) {
dispatch(devWorkspaceWarningUpdateAction({ workspace, warning: warnMessage }));
}
}

0 comments on commit 7ea3c7c

Please sign in to comment.