Next.js Discord

Discord Forum

Handle 504 gateway timeout error in Image

Unanswered
Transvaal lion posted this in #help-forum
Open in Discord
Transvaal lionOP
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>
  );
};

6 Replies

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 🙂