2023-07-29 11:43:15 +03:00
|
|
|
import type { ProblemDetailsError } from '../api-contract';
|
|
|
|
import { isInvalidArgumentError } from '../api-contract/utils';
|
2020-12-21 23:19:02 +03:00
|
|
|
|
2020-12-22 12:05:32 +03:00
|
|
|
export interface ShlinkApiErrorProps {
|
2020-12-21 23:19:02 +03:00
|
|
|
errorData?: ProblemDetailsError;
|
|
|
|
fallbackMessage?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const ShlinkApiError = ({ errorData, fallbackMessage }: ShlinkApiErrorProps) => (
|
|
|
|
<>
|
|
|
|
{errorData?.detail ?? fallbackMessage}
|
2022-03-26 14:17:42 +03:00
|
|
|
{isInvalidArgumentError(errorData) && (
|
|
|
|
<p className="mb-0">
|
|
|
|
Invalid elements: [{errorData.invalidElements.join(', ')}]
|
|
|
|
</p>
|
|
|
|
)}
|
2020-12-21 23:19:02 +03:00
|
|
|
</>
|
|
|
|
);
|