即刻空值检查 (#835)

This commit is contained in:
Henry Wang
2018-10-07 16:06:20 +08:00
committed by DIYgod
parent 3e62d481cf
commit 716b013ae1
4 changed files with 24 additions and 1 deletions
+8
View File
@@ -1,6 +1,14 @@
const url = require('url');
module.exports = {
emptyResponseCheck: (ctx, data) => {
if (data.length === 0) {
ctx.state.data = {
title: '主题 ID 不存在,或该主题暂无内容',
};
return true;
}
},
topicDataHanding: (data) =>
data.map((item) => {
let audioName, videoName, linkName;
+5 -1
View File
@@ -19,8 +19,12 @@ module.exports = async (ctx) => {
});
const data = response.data.data;
const topic = data[0].topic;
if (common.emptyResponseCheck(ctx, data)) {
return;
}
const topic = data[0].topic;
ctx.state.data = {
title: `${topic.content} - 即刻主题精选`,
link: `https://web.okjike.com/topic/${id}/official`,
+5
View File
@@ -19,6 +19,11 @@ module.exports = async (ctx) => {
});
const data = response.data.data;
if (common.emptyResponseCheck(ctx, data)) {
return;
}
const topic = data[0].topic;
ctx.state.data = {
+6
View File
@@ -1,5 +1,6 @@
const axios = require('../../utils/axios');
const dayjs = require('dayjs');
const common = require('./common');
module.exports = async (ctx) => {
const id = ctx.params.id;
@@ -19,6 +20,11 @@ module.exports = async (ctx) => {
});
const data = response.data.data;
if (common.emptyResponseCheck(ctx, data)) {
return;
}
const title = data[0].topic.content;
ctx.state.data = {