青鸟ai,pc版仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

69 lines
2.1 KiB

import type { ErrorMessageMode } from '/#/axios'
import { useMessage } from '@/hooks/useMessage'
import { useUserStore } from '@/store/moules/userStore/index'
import { HttpErrorMsgEnum } from '@/enums/httpEnum'
const { createMessage, createErrorModal } = useMessage()
const error = createMessage.error!
export function checkStatus(
status: number,
msg: string,
errorMessageMode: ErrorMessageMode = 'message',
): void {
const userStore = useUserStore()
let errMessage = ''
switch (status) {
case 400:
errMessage = msg || HttpErrorMsgEnum.API_REQUEST_FAILED
break
// 401: Not logged in
// Jump to the login page if not logged in, and carry the path of the current page
// Return to the current page after successful login. This step needs to be operated on the login page.
case 401:
errMessage = msg || HttpErrorMsgEnum.ERROR_MESSAGE_401
userStore.logout(true)
break
case 403:
errMessage = msg || HttpErrorMsgEnum.ERROR_MESSAGE_403
break
// 404请求不存在
case 404:
errMessage = msg || HttpErrorMsgEnum.ERROR_MESSAGE_404
break
case 405:
errMessage = msg || HttpErrorMsgEnum.ERROR_MESSAGE_405
break
case 408:
errMessage = msg || HttpErrorMsgEnum.ERROR_MESSAGE_408
break
case 500:
errMessage = msg || HttpErrorMsgEnum.ERROR_MESSAGE_500
break
case 501:
errMessage = msg || HttpErrorMsgEnum.ERROR_MESSAGE_501
break
case 502:
errMessage = msg || HttpErrorMsgEnum.ERROR_MESSAGE_502
break
case 503:
errMessage = msg || HttpErrorMsgEnum.ERROR_MESSAGE_503
break
case 504:
errMessage = msg || HttpErrorMsgEnum.ERROR_MESSAGE_504
break
case 505:
errMessage = msg || HttpErrorMsgEnum.ERROR_MESSAGE_505
break
default:
}
if (errMessage) {
if (errorMessageMode === 'modal')
createErrorModal({ title: HttpErrorMsgEnum.ERROR_TIP, content: errMessage })
else if (errorMessageMode === 'message')
error({ content: errMessage, key: `global_error_message_status_${status}` })
}
}