🚸 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

@@ -4,7 +4,7 @@ VITE_NODE_ENV='production'
VITE_APP_BASE_API='/sys' VITE_APP_BASE_API='/sys'
# 网站域名 # 网站域名
VITE_APP_WEB_URL='http://localhost:5173' VITE_APP_WEB_URL='https://www.landaiqing.cn'
# 网络请求公用地址 # 网络请求公用地址
VITE_API_BASE_URL='https://landaiqing.cn' VITE_API_BASE_URL='https://landaiqing.cn'
@@ -15,11 +15,11 @@ VITE_TITLE_NAME='五味子云相册'
VITE_APP_TOKEN_KEY='Bearer' VITE_APP_TOKEN_KEY='Bearer'
# the websocket url # the websocket url
VITE_QR_SOCKET_URL='wss://landaiqing.cn/api/ws/qr_ws' VITE_QR_SOCKET_URL='wss://landaiqing.cn/api/ws/qrcode'
VITE_MESSAGE_SOCKET_URL='wss://landaiqing.cn/api/ws/message_ws' VITE_MESSAGE_SOCKET_URL='wss://landaiqing.cn/api/ws/message'
VITE_FILE_SOCKET_URL='ws://127.0.0.1:80/api/ws/file' VITE_FILE_SOCKET_URL='wss://landaiqing.cn/api/ws/file'
# 签名密钥 # 签名密钥
VITE_FINGERPRINT_KEY='idm0jdoau38lwourb4pbjk4dxkat0kcx' VITE_FINGERPRINT_KEY='idm0jdoau38lwourb4pbjk4dxkat0kcx'

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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