diff --git a/shlink-web-component/src/tags/data/index.ts b/shlink-web-component/src/tags/data/index.ts index 14ec9adc..2c2eb507 100644 --- a/shlink-web-component/src/tags/data/index.ts +++ b/shlink-web-component/src/tags/data/index.ts @@ -1,4 +1,4 @@ -import type { ShlinkTagsStats } from '../../../api/types'; +import type { ShlinkTagsStats } from '@shlinkio/shlink-web-component/api-contract'; export type TagStats = Omit; diff --git a/shlink-web-component/src/visits/types/helpers.ts b/shlink-web-component/src/visits/types/helpers.ts index cc4b55f8..15dfa3c8 100644 --- a/shlink-web-component/src/visits/types/helpers.ts +++ b/shlink-web-component/src/visits/types/helpers.ts @@ -1,5 +1,5 @@ +import type { ShlinkVisitsParams } from '@shlinkio/shlink-web-component/api-contract'; import { countBy, groupBy, pipe, prop } from 'ramda'; -import type { ShlinkVisitsParams } from '../../../api/types'; import { formatIsoDate } from '../../utils/dates/helpers/date'; import type { CreateVisit, NormalizedOrphanVisit, NormalizedVisit, OrphanVisit, Stats, Visit, VisitsParams } from './index'; diff --git a/src/api/services/ShlinkApiClient.ts b/src/api/services/ShlinkApiClient.ts index b44c7805..89361fff 100644 --- a/src/api/services/ShlinkApiClient.ts +++ b/src/api/services/ShlinkApiClient.ts @@ -1,5 +1,6 @@ import { orderToString, stringifyQuery } from '@shlinkio/shlink-frontend-kit'; import type { + RegularNotFound, ShlinkApiClient as BaseShlinkApiClient, ShlinkDomainRedirects, ShlinkDomainsResponse, @@ -15,9 +16,11 @@ import type { ShlinkTagsStatsResponse, ShlinkVisits, ShlinkVisitsOverview, - ShlinkVisitsParams, + ShlinkVisitsParams } from '@shlinkio/shlink-web-component/api-contract'; +import { + ErrorTypeV2, + ErrorTypeV3, } from '@shlinkio/shlink-web-component/api-contract'; -import { isRegularNotFound, parseApiError } from '@shlinkio/shlink-web-component/api-contract/utils'; import { isEmpty, isNil, reject } from 'ramda'; import type { ShortUrl, ShortUrlData } from '../../../shlink-web-component/src/short-urls/data'; import type { HttpClient } from '../../common/services/HttpClient'; @@ -44,6 +47,13 @@ const normalizeListParams = ( excludePastValidUntil: excludePastValidUntil === true ? 'true' : undefined, orderBy: orderToString(orderBy), }); +const isRegularNotFound = (error: unknown): error is RegularNotFound => { + if (error === null || !(typeof error === 'object' && 'type' in error && 'status' in error)) { + return false; + } + + return (error.type === ErrorTypeV2.NOT_FOUND || error.type === ErrorTypeV3.NOT_FOUND) && error.status === 404; +}; export class ShlinkApiClient implements BaseShlinkApiClient { private apiVersion: ApiVersion; @@ -162,7 +172,7 @@ export class ShlinkApiClient implements BaseShlinkApiClient { }; private readonly handleFetchError = (retryFetch: Function) => (e: unknown) => { - if (!isRegularNotFound(parseApiError(e))) { + if (!isRegularNotFound(e)) { throw e; }