Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not dispatch a warning, if the git provider is not supported #1306

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
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
Expand Up @@ -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,
Expand Down Expand Up @@ -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 }));
}
}
Expand Down
Loading