Skip to content

Commit

Permalink
Do not eat exceptions and properly log errors
Browse files Browse the repository at this point in the history
Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <t.s.maeder@gmail.com>
  • Loading branch information
tsmaeder committed Jul 10, 2024
1 parent 48cb2b8 commit 6f60c21
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
1 change: 1 addition & 0 deletions dev-packages/cli/src/download-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export default async function downloadPlugins(ovsxClient: OVSXClient, requestSer
failures.push(`No download url for extension pack ${id} (${version})`);
}
} catch (err) {
console.error(err);
failures.push(err.message);
}
}));
Expand Down
24 changes: 4 additions & 20 deletions dev-packages/ovsx-client/src/ovsx-http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,12 @@ export class OVSXHttpClient implements OVSXClient {
protected requestService: RequestService
) { }

async search(searchOptions?: VSXSearchOptions): Promise<VSXSearchResult> {
try {
return await this.requestJson(this.buildUrl('api/-/search', searchOptions));
} catch (err) {
return {
error: err?.message || String(err),
offset: -1,
extensions: []
};
}
search(searchOptions?: VSXSearchOptions): Promise<VSXSearchResult> {
return this.requestJson(this.buildUrl('api/-/search', searchOptions));
}

async query(queryOptions?: VSXQueryOptions): Promise<VSXQueryResult> {
try {
return await this.requestJson(this.buildUrl('api/v2/-/query', queryOptions));
} catch (error) {
return {
offset: 0,
totalSize: 0,
extensions: []
};
}
query(queryOptions?: VSXQueryOptions): Promise<VSXQueryResult> {
return this.requestJson(this.buildUrl('api/v2/-/query', queryOptions));
}

protected async requestJson<R>(url: string): Promise<R> {
Expand Down
14 changes: 11 additions & 3 deletions dev-packages/request/src/node-request-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,19 @@ export class NodeRequestService implements RequestService {
});
});

stream.on('error', reject);
stream.on('error', err => {
reject(err);
});
}
});

req.on('error', reject);
req.on('error', err => {
reject(err);
});

req.on('timeout', () => {
reject('timeout');
});

if (options.timeout) {
req.setTimeout(options.timeout);
Expand All @@ -153,7 +161,7 @@ export class NodeRequestService implements RequestService {
req.end();

token?.onCancellationRequested(() => {
req.abort();
req.destroy();
reject();
});
});
Expand Down

0 comments on commit 6f60c21

Please sign in to comment.