Skip to content

Commit 431ef9f

Browse files
committed
Check and display file url errors
1 parent 8da22c7 commit 431ef9f

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

smoosense-gui/src/components/audio/AudioMiniMelSpectrogram.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const AudioMiniMelSpectrogram = memo(function AudioMiniMelSpectrogram({
6767
}, [])
6868

6969
// Only load audio when visible
70-
const { audioData, isLoading } = useAudioData(isVisible ? audioUrl : '')
70+
const { audioData, isLoading, error } = useAudioData(isVisible ? audioUrl : '')
7171

7272
// Extract or pad to 5 seconds, with trimming - save to state
7373
useEffect(() => {
@@ -127,10 +127,36 @@ const AudioMiniMelSpectrogram = memo(function AudioMiniMelSpectrogram({
127127
)
128128

129129
// Show placeholder until visible, or while loading
130-
if (!isVisible || isLoading || !previewSamples) {
130+
if (!isVisible || isLoading) {
131131
return loadingContent
132132
}
133133

134+
// Show error message if loading failed
135+
if (error) {
136+
return (
137+
<div
138+
ref={containerRef}
139+
className="w-full flex items-center justify-start bg-muted/20 text-destructive text-xs p-1 overflow-hidden"
140+
style={{ height }}
141+
>
142+
<span className="break-all line-clamp-3 text-left">{error.message}</span>
143+
</div>
144+
)
145+
}
146+
147+
// Show message if no audio data
148+
if (!previewSamples) {
149+
return (
150+
<div
151+
ref={containerRef}
152+
className="w-full flex items-center justify-center bg-muted/20 text-muted-foreground text-xs"
153+
style={{ height }}
154+
>
155+
No audio data
156+
</div>
157+
)
158+
}
159+
134160
const melSpectrogramContent = (
135161
<div className="w-full">
136162
<MelSpectrogram

smoosense-gui/src/components/audio/RichAudioPlayer.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function RichAudioPlayer({ audioUrl, autoPlay = false }: RichAudi
1717
const [currentTime, setCurrentTime] = useState(0)
1818

1919
// Load audio data (starts loading when this component mounts, i.e., when popover opens)
20-
const { audioData } = useAudioData(audioUrl)
20+
const { audioData, isLoading, error } = useAudioData(audioUrl)
2121

2222
// Handle seek from visualizations
2323
const handleSeek = (time: number) => {
@@ -33,10 +33,22 @@ export default function RichAudioPlayer({ audioUrl, autoPlay = false }: RichAudi
3333
}
3434
}
3535

36+
// Show error message if loading failed
37+
if (error) {
38+
return (
39+
<div className="p-4 w-full flex items-center justify-start h-[280px]">
40+
<div className="flex flex-col items-start space-y-3 text-destructive max-w-full overflow-hidden">
41+
<span className="text-sm font-medium">Failed to load audio</span>
42+
<span className="text-xs break-all line-clamp-3 text-left">{error.message}</span>
43+
</div>
44+
</div>
45+
)
46+
}
47+
3648
// Show loading spinner while audio is being downloaded/decoded
37-
if (!audioData) {
49+
if (isLoading || !audioData) {
3850
return (
39-
<div className="p-4 w-full flex items-center justify-center h-[500px]">
51+
<div className="p-4 w-full flex items-center justify-center h-[280px]">
4052
<div className="flex flex-col items-center space-y-3">
4153
<div className="w-12 h-12 border-4 border-muted-foreground border-t-transparent rounded-full animate-spin" />
4254
<span className="text-sm text-muted-foreground">Loading audio...</span>

smoosense-gui/src/lib/hooks/useAudioData.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ export function useAudioData(audioUrl: string): UseAudioDataResult {
4949
const response = await fetch(audioUrl)
5050
if (cancelled) return
5151

52+
if (!response.ok) {
53+
const status = response.status
54+
if (status === 401) {
55+
throw new Error(`Unauthorized: ${audioUrl}`)
56+
} else if (status === 403) {
57+
throw new Error(`Access denied: ${audioUrl}`)
58+
} else if (status === 404) {
59+
throw new Error(`File not found: ${audioUrl}`)
60+
} else if (status >= 500) {
61+
throw new Error(`Server error: ${audioUrl}`)
62+
}
63+
throw new Error(`HTTP error ${status}: ${audioUrl}`)
64+
}
65+
5266
const arrayBuffer = await response.arrayBuffer()
5367
if (cancelled) return
5468

0 commit comments

Comments
 (0)