Skip to content

Commit

Permalink
fix: silently failing image requests (#160)
Browse files Browse the repository at this point in the history
Failed image requests now fallback to label instead of breaking
  • Loading branch information
uhrjun authored Jul 16, 2024
1 parent 4c0d1b3 commit 28fdc04
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/Avatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
:class="[sizeClasses, shapeClasses]"
>
<img
v-if="image"
v-if="image && !imgFetchError"
:src="image"
:alt="label"
:class="[shapeClasses, 'h-full w-full object-cover']"
@error="(err) => handleImageError(err)"
/>
<div
v-else
Expand Down Expand Up @@ -36,7 +37,9 @@
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { ref, computed } from 'vue'
const imgFetchError = ref(false)
interface AvatarProps {
image?: string
Expand Down Expand Up @@ -125,4 +128,10 @@ const iconClasses = computed(() => {
'3xl': 'h-5 w-5',
}[props.size]
})
function handleImageError(err) {
if (err.type) {
imgFetchError.value = true
}
}
</script>

0 comments on commit 28fdc04

Please sign in to comment.