Next.js Discord

Discord Forum

How to set image not found if upstream image response failed

Answered
riktikdev posted this in #help-forum
Open in Discord
Hi 😊! I have a question is there any possibility to install another image like "404.png" from public folder if there is such case "upstream image response failed for https://desu.shikimori.one/system/animes/original/57569.jpg?1711837414 404"?
Answered by joulev
Try the suggestions here https://stackoverflow.com/q/34097560
View full answer

6 Replies

Like this
@riktikdev https://tenor.com/view/oa1sf9-gif-21020110
https://nextjs.org/docs/pages/building-your-application/routing/custom-error

Not sure if youre still facing this issue so just linking documentation, let me know if youre actively facing this and I can give some additional guidance

// import this at the top of the file
import Error from 'next/error'

// call this where you want to throw the 404 error
return <Error statusCode={404} />
@riktikdev Like this
Try the suggestions here https://stackoverflow.com/q/34097560
Answer
In a more complex use case I used to use this package https://www.npmjs.com/package/react-image though I doubt your use case needs as much as one new dependency