Handle 504 gateway timeout error in Image
Unanswered
Transvaal lion posted this in #help-forum
Transvaal lionOP
Hi all!
Is there a way to handle 504 gateway timeout error in Image component? I was trying to use
This is my Avatar component in which i'm trying to handle it
Is there a way to handle 504 gateway timeout error in Image component? I was trying to use
onError handler but it doesn't trigger it, gateway timeout usually appears after ~ 20 secondsThis is my Avatar component in which i'm trying to handle it
const Avatar: FC<AvatarProps> = ({ src, size }) => {
const { avatarSizeClass } = SIZES[size];
const handleOnError = (e: React.SyntheticEvent<HTMLImageElement, Event>) => {
e.currentTarget.src = DEFAULT_AVATAR_URL;
};
return (
<div
className={`flex items-center ${avatarSizeClass} bg-neutral-5 rounded-full overflow-hidden w-full h-full relative`}
>
<Image
src={src}
alt="avatar"
onError={handleOnError}
objectFit="cover"
layout="fill"
</div>
);
};6 Replies
@Transvaal lion Hi all!
Is there a way to handle 504 gateway timeout error in Image component? I was trying to use `onError` handler but it doesn't trigger it, gateway timeout usually appears after ~ 20 seconds
This is my Avatar component in which i'm trying to handle it
const Avatar: FC<AvatarProps> = ({ src, size }) => {
const { avatarSizeClass } = SIZES[size];
const handleOnError = (e: React.SyntheticEvent<HTMLImageElement, Event>) => {
e.currentTarget.src = DEFAULT_AVATAR_URL;
};
return (
<div
className={`flex items-center ${avatarSizeClass} bg-neutral-5 rounded-full overflow-hidden w-full h-full relative`}
>
<Image
src={src}
alt="avatar"
onError={handleOnError}
objectFit="cover"
layout="fill"
</div>
);
};
hi, try this
"use client";
import Image from "next/image";
import { useState } from "react";
export default function Img() {
const [error, setError] = useState(false);
const defaultUrl =
"";
return (
<Image
src={error ? defaultUrl : "http://sdf.com/dfdf"}
alt=""
width={400}
height={280}
onError={(e) => {
setError(true);
}}
/>
);
}Transvaal lionOP
main issue here is, that it doesn't trigger
onError at all :/do you have a link which cause 504 that I can try?
@Ray do you have a link which cause 504 that I can try?
Transvaal lionOP
yup! try this
https://gw.ipfs-lens.dev/ipfs/QmQTKBTBRgUt43Yz3cvd5NC2vyBB98Vf7EnBYXKLscyDQJ@Transvaal lion yup! try this `https://gw.ipfs-lens.dev/ipfs/QmQTKBTBRgUt43Yz3cvd5NC2vyBB98Vf7EnBYXKLscyDQJ`
oh yea it doesn't trigger the error, look like you need to check the link yourself
@Ray oh yea it doesn't trigger the error, look like you need to check the link yourself
Transvaal lionOP
gotcha! thanks for helping out 🙂