Skip to content

Commit

Permalink
fix: an error when passing the editor's devfile link
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <oorel@redhat.com>
  • Loading branch information
olexii4 committed Mar 7, 2023
1 parent 34adfc0 commit f41f79f
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ import { AUTHORIZED, SanityCheckAction } from '../../sanityCheckMiddleware';
import * as DwServerConfigStore from '../../ServerConfig';
import { selectOpenVSXUrl } from '../../ServerConfig/selectors';
import { fetchResources } from '../../../services/dashboard-backend-client/devworkspaceResourcesApi';
import { dump } from 'js-yaml';
import { dump, load } from 'js-yaml';
import { loadResourcesContent } from '../../../services/registry/resources';
import { checkRunningWorkspacesLimit } from './checkRunningWorkspacesLimit';
import { selectDevWorkspacesResourceVersion } from './selectors';
import { EDITOR_ATTR } from '../../../containers/Loader/const';
import axios from 'axios';

const devWorkspaceClient = container.get(DevWorkspaceClient);

Expand Down Expand Up @@ -544,8 +545,19 @@ export const actionCreators: ActionCreators = {
let editorContent: string | undefined;
// do we have an optional editor parameter ?
if (attributes[EDITOR_ATTR]) {
editorEntry = attributes[EDITOR_ATTR];
editorContent = undefined;
if (/^(https?:)/.test(attributes[EDITOR_ATTR])) {
const response = await axios.get<string>(attributes[EDITOR_ATTR], {
responseType: 'text',
});
if (response.data) {
editorContent = response.data;
} else {
throw new Error('Failed to find an Editor in the fetched resources.');
}
} else {
editorEntry = attributes[EDITOR_ATTR];
editorContent = undefined;
}
if (editorEntry !== defaultEditorEntry) {
console.log(
`User specified a different editor than the current default. Loading ${editorEntry} definition instead of ${defaultEditorEntry}.`,
Expand Down

0 comments on commit f41f79f

Please sign in to comment.