fix(route): /bilibili/user/video(article) Broken for some uploaders (#12992)

* Fix /bilibili/user/video Error message: Cannot read properties of undefined (reading 'name')

* /bilibili/user/video returns error message if fail to fetch
This commit is contained in:
JimenezLi
2023-08-11 20:48:04 +08:00
committed by GitHub
parent 54c0b9871b
commit 90c4c7ea4d
2 changed files with 8 additions and 3 deletions
+5 -3
View File
@@ -71,7 +71,7 @@ module.exports = {
Cookie: cookie,
},
});
return nameResponse.data.name;
return nameResponse.data ? nameResponse.data.name : undefined;
});
},
getUsernameAndFaceFromUID: async (ctx, uid) => {
@@ -95,8 +95,10 @@ module.exports = {
Cookie: cookie,
},
});
name = nameResponse.data.name;
face = nameResponse.data.face;
if (nameResponse.data) {
name = nameResponse.data.name;
face = nameResponse.data.face;
}
ctx.cache.set(nameKey, name);
ctx.cache.set(faceKey, face);
}
+3
View File
@@ -23,6 +23,9 @@ module.exports = async (ctx) => {
},
});
const data = response.data;
if (data.code) {
throw new Error(`Got error code ${data.code} while fetching: ${data.message}`);
}
ctx.state.data = {
title: `${name} 的 bilibili 空间`,