🚸 optimized error response

This commit is contained in:
2024-12-18 16:26:52 +08:00
parent 68a8e3e5c4
commit 8ab873f5ce
23 changed files with 69 additions and 38 deletions

View File

@@ -9,7 +9,7 @@ export const uploadImage = (data: uploadImageRequest) => {
}, {
meta: {
ignoreToken: false,
signature: true
signature: false,
}
});
};

View File

@@ -171,7 +171,7 @@ async function commentSubmit(point: any) {
key: comment.slideCaptchaData.captKey,
};
const result: any = await commentSubmitApi(commentParams);
if (result.code === 200) {
if (result && result.code === 200) {
const tmpData: any = {
user_id: user.user.uid,
content: result.data.content,

View File

@@ -172,7 +172,6 @@ import {
} from "@ant-design/icons-vue";
import {useThrottleFn} from "@vueuse/core";
import useStore from "@/store";
import {useRouter} from "vue-router";
import ReplyInput from "@/components/CommentReply/src/ReplyInput/ReplyInput.vue";
import ReplyList from "@/components/CommentReply/src/ReplyList/ReplyList.vue";
import MessageReport from "@/components/CommentReply/src/MessageReport/MessageReport.vue";
@@ -181,6 +180,7 @@ import UserInfoCard from "@/components/CommentReply/src/UserInfoCard/UserInfoCar
const {t} = useI18n();
const router = useRouter();
const route =useRoute();
const comment = useStore().comment;
@@ -274,7 +274,7 @@ async function cancelCommentLike(item: any) {
*/
async function paginationCommentChange(page: number, pageSize: number) {
router.push({
path: "/main",
path: route.path,
query: {
type: router.currentRoute.value.query.type,
page: page,
@@ -290,7 +290,7 @@ async function getHotCommentList() {
comment.commentLoading = true;
getCommentList(1, 5, true).then(() => {
router.push({
path: "/main",
path: route.path,
query: {
type: "hot",
page: router.currentRoute.value.query.page,
@@ -308,7 +308,7 @@ async function getLatestCommentList() {
comment.commentLoading = true;
getCommentList(1, 5, false).then(() => {
router.push({
path: "/main",
path: route.path,
query: {
type: "latest",
page: router.currentRoute.value.query.page,

View File

@@ -186,7 +186,7 @@ async function replySubmit(point: any) {
key: comment.slideCaptchaData.captKey,
};
const result: any = await replySubmitApi(replyParams);
if (result.code === 200) {
if (result && result.code === 200) {
const tmpData: any = {
id: result.data.id,
content: result.data.content,

View File

@@ -189,7 +189,7 @@ async function replyReplySubmit(point: any) {
key: comment.slideCaptchaData.captKey,
};
const result: any = await replyReplySubmitApi(replyParams);
if (result.code === 200) {
if (result && result.code === 200) {
const tmpData: any = {
id: result.data.id,
content: result.data.content,

View File

@@ -53,7 +53,7 @@ export const useCommentStore = defineStore(
commentList.value = {} as Comment;
// 获取评论列表
const result: any = await commentListApi(data);
if (result.code === 200 && result.data) {
if (result && result.code === 200) {
commentList.value = result.data;
if (Array.isArray(commentList.value.comments)) {
commentList.value.comments.map((item: any) => {
@@ -116,7 +116,7 @@ export const useCommentStore = defineStore(
async function getReplyList(data: any) {
// 获取评论列表
const result: any = await replyListApi(data);
if (result.code === 200 && result.data) {
if (result && result.code === 200) {
if (replyVisibility.value[data.comment_id].data !== result.data) {
replyVisibility.value[data.comment_id].data = result.data;
}
@@ -135,7 +135,7 @@ export const useCommentStore = defineStore(
topic_id: data.topic_id,
};
const result: any = await commentLikeApi(params);
if (result.code !== 200) {
if (result && result.code !== 200) {
message.error(result.message);
return false;
}
@@ -152,7 +152,7 @@ export const useCommentStore = defineStore(
topic_id: data.topic_id,
};
const result: any = await cancelCommentLikeApi(params);
if (result.code !== 200) {
if (result && result.code !== 200) {
message.error(result.message);
return false;
}
@@ -164,7 +164,7 @@ export const useCommentStore = defineStore(
*/
async function getSlideCaptchaData(): Promise<boolean> {
const res: any = await getSlideCaptchaDataApi();
if (res.code == 200 && res.data) {
if (res && res.code === 200) {
const {key, image, thumb, thumb_width, thumb_height, thumb_x, thumb_y} = res.data;
slideCaptchaData.captKey = key;
slideCaptchaData.image = image;

View File

@@ -31,7 +31,7 @@ export const useAuthStore = defineStore(
*/
async function getGithubRedirectUrl() {
const res: any = await getGithubUrl(clientId.value);
if (res.code === 200 && res.data) {
if (res && res.code === 200 && res.data) {
githubRedirectUrl.value = res.data;
}
}
@@ -41,7 +41,7 @@ export const useAuthStore = defineStore(
*/
async function getGiteeRedirectUrl() {
const res: any = await getGiteeUrl();
if (res.code === 200 && res.data) {
if (res && res.code === 200) {
giteeRedirectUrl.value = res.data;
}
}
@@ -51,7 +51,7 @@ export const useAuthStore = defineStore(
*/
async function getQQRedirectUrl() {
const res: any = await getQQUrl(clientId.value);
if (res.code === 200 && res.data) {
if (res && res.code === 200) {
qqRedirectUrl.value = res.data;
}
}
@@ -61,7 +61,7 @@ export const useAuthStore = defineStore(
*/
async function getClientId() {
const res: any = await generateClientId();
if (res.code === 200 && res.data) {
if (res && res.code === 200) {
clientId.value = res.data;
}
}
@@ -73,7 +73,7 @@ export const useAuthStore = defineStore(
const messageHandler = async (e: any) => {
if (typeof e.data === 'string') {
const res: any = JSON.parse(e.data);
if (res.code === 200 && res.data) {
if (res && res.code === 200) {
user.uid = res.data.uid;
user.access_token = res.data.access_token;
user.username = res.data.username;
@@ -84,7 +84,7 @@ export const useAuthStore = defineStore(
message.success(t('login.loginSuccess'));
window.removeEventListener("message", messageHandler);
setTimeout(() => {
router.push('/main');
router.push('/main/photo/all');
}, 1000);
} else {
message.error(t('login.loginError'));

View File

@@ -27,7 +27,7 @@ const {onAuthRequired, onResponseRefreshToken} = createServerTokenAuthentication
// 刷新token
const user = useStore().user;
const res: any = await refreshToken();
if (res.code === 200 && res.data) {
if (res && res.code === 200) {
user.user.access_token = res.data;
}
}

View File

@@ -263,7 +263,7 @@ async function resetPasswordSubmit() {
.validate()
.then(async () => {
const res: any = await resetPasswordApi(ResetPasswordForm);
if (res.code === 200 && res.data) {
if (res && res.code === 200) {
message.success(t('login.resetPasswordSuccess'));
router.push('/login');
} else {
@@ -285,7 +285,7 @@ const refreshCaptcha = useDebounceFn(getRotateCaptcha, 3000);
*/
async function getRotateCaptcha() {
const data: any = await getRotatedCaptchaData();
if (data.code === 200 && data.data) {
if (data && data.code === 200) {
const {image, thumb, key} = data.data;
captchaData.image = image;
captchaData.thumb = thumb;
@@ -300,7 +300,7 @@ async function getRotateCaptcha() {
*/
async function sendMessageByPhone(param: any): Promise<boolean> {
const res: any = await sendMessage(param);
if (res.code === 200 && res.data) {
if (res && res.code === 200) {
message.success(t('login.sendCaptchaSuccess'));
return true;
} else {

View File

@@ -372,7 +372,7 @@ async function phoneLoginSubmit() {
.then(async () => {
loginLoading.value = true;
const res: any = await phoneLoginApi(phoneLoginForm);
if (res.code === 200 && res.data) {
if (res && res.code === 200) {
userStore.user.uid = res.data.uid;
userStore.user.access_token = res.data.access_token;
userStore.user.username = res.data.username;
@@ -382,7 +382,7 @@ async function phoneLoginSubmit() {
message.success(t('login.loginSuccess'));
loginLoading.value = false;
setTimeout(() => {
router.push('/main');
router.push('/main/photo/all');
}, 1000);
} else {
loginLoading.value = false;
@@ -410,7 +410,7 @@ async function getRotateCaptcha() {
accountLoginRotateRef.value?.clear();
}
const data: any = await getRotatedCaptchaData();
if (data.code === 200 && data.data) {
if (data && data.code === 200) {
const {image, thumb, key} = data.data;
captchaData.image = image;
captchaData.thumb = thumb;
@@ -459,7 +459,7 @@ async function checkAccountLoginCaptcha(angle: number) {
};
loginLoading.value = true;
const res: any = await accountLoginApi(params);
if (res.code === 200 && res.data) {
if (res && res.code === 200) {
userStore.user.uid = res.data.uid;
userStore.user.access_token = res.data.access_token;
userStore.user.username = res.data.username;
@@ -470,7 +470,7 @@ async function checkAccountLoginCaptcha(angle: number) {
loginLoading.value = false;
showAccountRotateCaptcha.value = false;
setTimeout(() => {
router.push('/main');
router.push('/main/photo/all');
}, 1000);
} else {
loginLoading.value = false;
@@ -484,7 +484,7 @@ async function checkAccountLoginCaptcha(angle: number) {
*/
async function sendMessageByPhone(params: any): Promise<boolean> {
const res: any = await sendMessage(params);
if (res.code === 200) {
if (res && res.code === 200) {
message.success(t('login.sendCaptchaSuccess'));
return true;
} else {

View File

@@ -84,7 +84,7 @@ async function sendImage() {
user_id: route.query.user_id as string,
};
const res: any = await uploadImage(data);
if (res && res.code === 200) {
if (res && res && res.code === 200) {
message.success(t('upload.uploadSuccess'));
} else {
message.error(res.message);

View File

@@ -70,7 +70,7 @@ const userStore = useStore().user;
*/
async function getQrCode() {
const res: any = await generateQrCode(userStore.clientId);
if (res.code === 200 && res.data) {
if (res && res.code === 200) {
status.value = 'active';
qrcode.value = res.data;
await handleListenMessage();
@@ -92,7 +92,7 @@ async function handleListenMessage() {
websocket.initialize(wsOptions);
// 注册消息接收处理函数
websocket.on('message', async (res: any) => {
if (res.code === 200 && res.data) {
if (res && res.code === 200) {
userStore.user.uid = res.data.uid;
userStore.user.access_token = res.data.access_token;
userStore.user.username = res.data.username;
@@ -103,7 +103,7 @@ async function handleListenMessage() {
await getUserDevice();
message.success(t('login.loginSuccess'));
setTimeout(() => {
router.push('/main');
router.push('/main/photo/all');
}, 1000);
}
});

View File

@@ -35,7 +35,7 @@ const wsOptions = {
onMounted(() => {
websocket.initialize(wsOptions);
websocket.on("message", async (res: any) => {
if (res && res.code === 200) {
if (res && res && res.code === 200) {
const {data} = res;
img.src = data;
await upscale.loadImg(img);