Skip to content

Commit d608d58

Browse files
added catch block
Signed-off-by: msivasubramaniaan <msivasub@redhat.com>
1 parent bdf166b commit d608d58

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/registriesView.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
139139
}
140140
});
141141
});
142+
}).catch(() => {
143+
this.subject.next('error');
142144
});
143145
}
144146

src/webview/devfile-registry/app/home.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ export const Home: React.FC<DefaultProps> = ({ }) => {
5656
const [filteredcompDescriptions, setFilteredcompDescriptions] = React.useState([]);
5757
const [registries, setRegistries] = React.useState([]);
5858
const [searchValue, setSearchValue] = React.useState('');
59-
const [error, setError] = React.useState(false);
59+
const [error, setError] = React.useState('');
6060

6161
React.useEffect(() => {
6262
return VSCodeMessage.onMessage((message) => {
6363
if (message.data.action === 'getAllComponents') {
64-
if (message.data.error) {
65-
setError(message.data.error);
64+
if (message.data.errorMessage && message.data.errorMessage.length > 0) {
65+
setError(message.data.errorMessage);
6666
} else {
67-
setError(false);
67+
setError('');
6868
message.data.registries.map((registry: Registry) => {
6969
if (registry.URL.toLowerCase().indexOf('https://registry.devfile.io') !== -1) {
7070
registry.state = true;
@@ -75,7 +75,7 @@ export const Home: React.FC<DefaultProps> = ({ }) => {
7575
setFilteredcompDescriptions(getFilteredCompDesc(message.data.registries, message.data.compDescriptions, searchValue));
7676
}
7777
} else if (message.data.action === 'loadingComponents') {
78-
setError(false);
78+
setError('');
7979
setFilteredcompDescriptions([]);
8080
setCompDescriptions([]);
8181
setSearchValue('');
@@ -120,10 +120,10 @@ export const Home: React.FC<DefaultProps> = ({ }) => {
120120
/>
121121
}
122122
<HomeItem compDescriptions={filteredcompDescriptions} />
123-
{error ? <ErrorPage message='Devfiles not downloaded properly' /> : null}
123+
{error?.length > 0 ? <ErrorPage message='Devfiles not downloaded properly' /> : null}
124124
</>
125125
:
126-
error ? <ErrorPage message='500: Internal Sever Error' /> : <LoadScreen />
126+
error?.length > 0 ? <ErrorPage message={error} /> : <LoadScreen />
127127
}
128128
</>
129129
);

src/webview/devfile-registry/registryViewLoader.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,15 @@ export default class RegistryViewLoader {
122122
}
123123
}
124124

125-
function getAllComponents(eventActionName: string) {
125+
function getAllComponents(eventActionName: string, error?: string) {
126126
const registries = ComponentTypesView.instance.getListOfRegistries();
127127
const componentDescriptions = ComponentTypesView.instance.getCompDescriptions();
128128
panel?.webview.postMessage(
129129
{
130130
action: eventActionName,
131131
compDescriptions: Array.from(componentDescriptions),
132-
registries: registries
132+
registries: registries,
133+
errorMessage: error
133134
}
134135
);
135136
}
@@ -138,5 +139,7 @@ ComponentTypesView.instance.subject.subscribe((value: string) => {
138139
if (value === 'refresh') {
139140
RegistryViewLoader.refresh();
140141
getAllComponents('getAllComponents');
142+
} else if (value === 'error') {
143+
getAllComponents('getAllComponents', 'Devfile Registry is not accessible');
141144
}
142145
});

0 commit comments

Comments
 (0)