Skip to content

Commit

Permalink
Do not dispatch a warning, if the git provider is not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Jan 28, 2025
1 parent 6c0d01f commit 7ea3c7c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
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

0 comments on commit 7ea3c7c

Please sign in to comment.