diff --git a/tabby-plugin-manager/src/components/pluginsSettingsTab.component.ts b/tabby-plugin-manager/src/components/pluginsSettingsTab.component.ts index d45225b74..f798191c6 100644 --- a/tabby-plugin-manager/src/components/pluginsSettingsTab.component.ts +++ b/tabby-plugin-manager/src/components/pluginsSettingsTab.component.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker' -import { BehaviorSubject, Observable, debounceTime, distinctUntilChanged, first, tap, switchMap, map } from 'rxjs' +import { BehaviorSubject, Observable, debounceTime, distinctUntilChanged, first, finalize, switchMap, map } from 'rxjs' import semverGt from 'semver/functions/gt' import { Component, HostBinding, Input } from '@angular/core' @@ -50,7 +50,7 @@ export class PluginsSettingsTabComponent { distinctUntilChanged(), switchMap(query => { this.availablePluginsReady = false - return this.pluginManager.listAvailable(query).pipe(tap(() => { + return this.pluginManager.listAvailable(query).pipe(finalize(() => { this.availablePluginsReady = true })) }), diff --git a/tabby-plugin-manager/src/services/pluginManager.service.ts b/tabby-plugin-manager/src/services/pluginManager.service.ts index 0d1f312e6..5042bffa0 100644 --- a/tabby-plugin-manager/src/services/pluginManager.service.ts +++ b/tabby-plugin-manager/src/services/pluginManager.service.ts @@ -1,5 +1,5 @@ import { compare as semverCompare, valid as semverValid } from 'semver' -import { Observable, from, forkJoin, map, of } from 'rxjs' +import { Observable, from, forkJoin, map, of, catchError } from 'rxjs' import { Injectable, Inject } from '@angular/core' import { Logger, LogService, PlatformService, BOOTSTRAP_DATA, BootstrapData, PluginInfo } from 'tabby-core' import { PLUGIN_BLACKLIST } from '../../../app/src/pluginBlacklist' @@ -50,7 +50,16 @@ export class PluginManagerService { _listAvailableInternal (namePrefix: string, keyword: string, query?: string): Observable { return from( - fetch(`https://registry.npmjs.com/-/v1/search?text=keywords%3A${keyword}%20${query}&size=250`).then(r => r.json()), + fetch(`https://registry.npmjs.com/-/v1/search?text=${encodeURIComponent(`keywords:${keyword} ${query ?? ''}`)}&size=250`).then(async r => { + if (!r.ok) { + throw new Error(`npm search failed: ${r.status}`) + } + const response = await r.json() + if (!Array.isArray(response.objects)) { + throw new Error('npm search returned an invalid response') + } + return response + }), ).pipe( map(response => response.objects .filter(item => !item.keywords?.includes('tabby-dummy-transition-plugin')) @@ -80,6 +89,10 @@ export class PluginManagerService { }) }), map(plugins => plugins.sort((a, b) => a.name.localeCompare(b.name))), + catchError(err => { + this.logger.error('Failed to search available plugins', err) + return of([]) + }), ) }