| 40 | } |
| 41 | |
| 42 | const fetchPhoto = async (photoId: string) => { |
| 43 | console.info(`Fetching photo with id ${photoId}...`) |
| 44 | await new Promise((r) => setTimeout(r, 500)) |
| 45 | |
| 46 | // Simulate photo not found for invalid IDs |
| 47 | const photoIdNum = parseInt(photoId, 10) |
| 48 | if (isNaN(photoIdNum) || photoIdNum < 1 || photoIdNum > 10) { |
| 49 | throw new NotFoundError(`Photo with id "${photoId}" not found!`) |
| 50 | } |
| 51 | |
| 52 | // Generate mock photo using picsum.photos |
| 53 | return { |
| 54 | id: photoId, |
| 55 | title: `Photo ${photoId}`, |
| 56 | url: `https://picsum.photos/600/400?random=${photoId}`, |
| 57 | thumbnailUrl: `https://picsum.photos/200/200?random=${photoId}`, |
| 58 | albumId: '1', |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | type PhotoModal = { |
| 63 | id: 'photo' |