BambitTestTask/api/httpClient.ts
2025-11-17 18:40:04 +03:00

22 lines
425 B
TypeScript

import { useToast } from '#imports'
const showToast = (description: string) => {
if (!import.meta.client)
return
const toast = useToast()
toast.add({
title: 'Uh oh! Something went wrong.',
description,
})
}
export const httpClient = $fetch.create({
onResponseError({ request, response }) {
const message = response?._data?.statusMessage ?? 'Something went wrong'
showToast(message)
},
})