Remove artificial delay from apiError, show toast immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,33 +6,18 @@
|
||||
// cindy.chang@dsp.im (Cindy Chang), 2024/5/30
|
||||
/** @module apiError Centralized API error handler with toast notifications. */
|
||||
|
||||
import { useLoadingStore } from '@/stores/loading';
|
||||
import {useToast} from 'vue-toast-notification';
|
||||
import 'vue-toast-notification/dist/theme-sugar.css';
|
||||
|
||||
/**
|
||||
* Returns a promise that resolves after the specified milliseconds.
|
||||
* @param {number} [s=0] - The delay in milliseconds.
|
||||
* @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
|
||||
* Handles API errors by showing a toast notification.
|
||||
* 401 errors are handled by the axios response interceptor
|
||||
* in api/client.js.
|
||||
*
|
||||
* @param {Object} error - The error object from the API call.
|
||||
* @param {string} toastMessage - The message to display in the toast.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export default async function apiError(error, toastMessage) {
|
||||
const loading = useLoadingStore();
|
||||
export default function apiError(error, toastMessage) {
|
||||
const $toast = useToast();
|
||||
await delay();
|
||||
loading.isLoading = true;
|
||||
await delay(1000);
|
||||
loading.isLoading = false;
|
||||
await delay(500);
|
||||
$toast.default(toastMessage, {position: 'bottom'});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user