diff --git a/src/short-urls/helpers/DeleteShortUrlModal.tsx b/src/short-urls/helpers/DeleteShortUrlModal.tsx
index 35f99cf4..9fd714f9 100644
--- a/src/short-urls/helpers/DeleteShortUrlModal.tsx
+++ b/src/short-urls/helpers/DeleteShortUrlModal.tsx
@@ -5,8 +5,7 @@ import { ShortUrlDeletion } from '../reducers/shortUrlDeletion';
import { ShortUrlModalProps } from '../data';
import { handleEventPreventingDefault, OptionalString } from '../../utils/utils';
import { Result } from '../../utils/Result';
-
-const THRESHOLD_REACHED = 'INVALID_SHORTCODE_DELETION';
+import { isInvalidDeletionError } from '../../utils/services/types';
interface DeleteShortUrlModalConnectProps extends ShortUrlModalProps {
shortUrlDeletion: ShortUrlDeletion;
@@ -22,9 +21,6 @@ const DeleteShortUrlModal = (
useEffect(() => resetDeleteShortUrl, []);
const { error, errorData } = shortUrlDeletion;
- const errorCode = error && errorData?.type;
- const hasThresholdError = errorCode === THRESHOLD_REACHED;
- const hasErrorOtherThanThreshold = error && errorCode !== THRESHOLD_REACHED;
const close = pipe(resetDeleteShortUrl, toggle);
const handleDeleteUrl = handleEventPreventingDefault(() => {
const { shortCode, domain } = shortUrl;
@@ -53,15 +49,15 @@ const DeleteShortUrlModal = (
onChange={(e) => setInputValue(e.target.value)}
/>
- {hasThresholdError && (
+ {error && isInvalidDeletionError(errorData) && (
- {errorData?.threshold && `This short URL has received more than ${errorData.threshold} visits, and therefore, it cannot be deleted.`}
- {!errorData?.threshold && 'This short URL has received too many visits, and therefore, it cannot be deleted.'}
+ {errorData.threshold && `This short URL has received more than ${errorData.threshold} visits, and therefore, it cannot be deleted.`}
+ {!errorData.threshold && 'This short URL has received too many visits, and therefore, it cannot be deleted.'}
)}
- {hasErrorOtherThanThreshold && (
+ {error && !isInvalidDeletionError(errorData) && (
- Something went wrong while deleting the URL :(
+ {errorData?.detail ?? 'Something went wrong while deleting the URL :('}
)}
diff --git a/src/utils/services/types.ts b/src/utils/services/types.ts
index ae50c352..b515ff06 100644
--- a/src/utils/services/types.ts
+++ b/src/utils/services/types.ts
@@ -77,10 +77,18 @@ export interface ProblemDetailsError {
[extraProps: string]: any;
}
-export interface InvalidArgumentError extends ProblemDetailsError {
+interface InvalidArgumentError extends ProblemDetailsError {
type: 'INVALID_ARGUMENT';
invalidElements: string[];
}
+interface InvalidShortUrlDeletion extends ProblemDetailsError {
+ type: 'INVALID_SHORTCODE_DELETION';
+ threshold?: number;
+}
+
export const isInvalidArgumentError = (error?: ProblemDetailsError): error is InvalidArgumentError =>
error?.type === 'INVALID_ARGUMENT';
+
+export const isInvalidDeletionError = (error?: ProblemDetailsError): error is InvalidShortUrlDeletion =>
+ error?.type === 'INVALID_SHORTCODE_DELETION';