Fix API error details and add toast info

This commit is contained in:
MartinBraquet
2026-03-15 14:31:42 +01:00
parent 3d1e91d100
commit f83dbf349e
2 changed files with 8 additions and 5 deletions

View File

@@ -50,7 +50,7 @@ export async function typedAPICall<P extends APIPath>(
}
if (!resp.ok) {
throw new APIError(resp.status as any, json?.message, json?.details)
throw new APIError(resp.status as any, json?.error?.message, json?.error?.details)
}
return json
}) as APIResponse<P>

View File

@@ -1,3 +1,4 @@
import {APIError} from 'common/api/utils'
import {debug} from 'common/logger'
import {Profile, ProfileWithoutUser} from 'common/profiles/profile'
import {BaseUser, User} from 'common/user'
@@ -85,10 +86,12 @@ function ProfilePageInner(props: {user: User; profile: Profile}) {
try {
await Promise.all(promises)
} catch (error) {
console.error(error)
toast.error(
`We ran into an issue saving your profile. Please try again or contact us if the issue persists.`,
)
let message =
'We ran into an issue saving your profile. Please try again or contact us if the issue persists.'
if (error instanceof APIError) {
message = `Error: ` + JSON.stringify(error.toJSON().error.details)
}
toast.error(message)
return
}
Router.push(`/${user.username}`)