Remove artificial delay from apiError, show toast immediately

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 08:59:52 +08:00
parent 589783d481
commit cd71815c97

View File

@@ -6,33 +6,18 @@
// cindy.chang@dsp.im (Cindy Chang), 2024/5/30 // cindy.chang@dsp.im (Cindy Chang), 2024/5/30
/** @module apiError Centralized API error handler with toast notifications. */ /** @module apiError Centralized API error handler with toast notifications. */
import { useLoadingStore } from '@/stores/loading';
import {useToast} from 'vue-toast-notification'; import {useToast} from 'vue-toast-notification';
import 'vue-toast-notification/dist/theme-sugar.css'; import 'vue-toast-notification/dist/theme-sugar.css';
/** /**
* Returns a promise that resolves after the specified milliseconds. * Handles API errors by showing a toast notification.
* @param {number} [s=0] - The delay in milliseconds. * 401 errors are handled by the axios response interceptor
* @returns {Promise<void>} A promise that resolves after the delay.
*/
const delay = (s = 0) => new Promise((resolve, reject) => setTimeout(resolve, s));
/**
* Handles API errors by showing a loading spinner followed by a toast
* notification. 401 errors are handled by the axios response interceptor
* in api/client.js. * in api/client.js.
* *
* @param {Object} error - The error object from the API call. * @param {Object} error - The error object from the API call.
* @param {string} toastMessage - The message to display in the toast. * @param {string} toastMessage - The message to display in the toast.
* @returns {Promise<void>}
*/ */
export default async function apiError(error, toastMessage) { export default function apiError(error, toastMessage) {
const loading = useLoadingStore();
const $toast = useToast(); const $toast = useToast();
await delay();
loading.isLoading = true;
await delay(1000);
loading.isLoading = false;
await delay(500);
$toast.default(toastMessage, {position: 'bottom'}); $toast.default(toastMessage, {position: 'bottom'});
} }