search-error.ts 637 B

1234567891011121314151617181920212223242526
  1. import ExtensibleCustomError from 'extensible-custom-error';
  2. import type { AllTermsKey } from '~/server/interfaces/search';
  3. export class SearchError extends ExtensibleCustomError {
  4. readonly id = 'SearchError';
  5. unavailableTermsKeys!: AllTermsKey[];
  6. constructor(message = '', unavailableTermsKeys: AllTermsKey[]) {
  7. super(message);
  8. this.unavailableTermsKeys = unavailableTermsKeys;
  9. }
  10. }
  11. export const isSearchError = (err: any): err is SearchError => {
  12. if (err == null || typeof err !== 'object') {
  13. return false;
  14. }
  15. if (err instanceof SearchError) {
  16. return true;
  17. }
  18. return err?.id === 'SearchError';
  19. };