better error handling and more Logan logging

master
rob 1 year ago
parent 4799e429a0
commit d1574e519a

@ -78,7 +78,7 @@ class AdminController extends SiteController {
});
}
async getHomeView (req, res) {
async getHomeView (req, res, next) {
const {
chat: chatService,
coreNode: coreNodeService,
@ -87,28 +87,36 @@ class AdminController extends SiteController {
logan: loganService,
user: userService,
} = this.dtp.services;
res.locals.stats = {
userSignupHourly: await dashboardService.getUserSignupsPerHour(),
memberCount: await User.estimatedDocumentCount(),
constellation: await coreNodeService.getConstellationStats(),
};
res.locals.channels = await venueService.getChannels();
res.locals.pageTitle = `Admin Dashbord for ${this.dtp.config.site.name}`;
res.locals.recentMembers = await userService.getRecent(10);
res.locals.admins = await userService.getAdmins();
res.locals.moderators = await userService.getModerators();
res.locals.recentChat = await chatService.getRecent(10);
loganService.sendRequestEvent(module.exports, req, {
level: 'info',
event: 'getHomeView',
});
res.render('admin/index');
try {
res.locals.pageTitle = `Admin Dashbord for ${this.dtp.config.site.name}`;
res.locals.stats = {
userSignupHourly: await dashboardService.getUserSignupsPerHour(),
memberCount: await User.estimatedDocumentCount(),
constellation: await coreNodeService.getConstellationStats(),
};
try {
res.locals.channels = await venueService.getChannels();
} catch (error) {
// fall through
res.locals.channels = [ ];
}
res.locals.recentMembers = await userService.getRecent(10);
res.locals.admins = await userService.getAdmins();
res.locals.moderators = await userService.getModerators();
res.locals.recentChat = await chatService.getRecent(10);
loganService.sendRequestEvent(module.exports, req, {
level: 'info',
event: 'getHomeView',
});
res.render('admin/index');
} catch (error) {
return next(error);
}
}
}

@ -92,12 +92,12 @@ class VenueService extends SiteService {
widgetKey: channelDefinition['credentials.widgetKey'].trim(),
};
const status = await this.updateChannelStatus(channel);
channel.name = status.name;
channel.description = status.description;
await channel.save();
await this.updateChannelStatus(channel);
channel.currentStatus = await this.updateChannelStatus(channel);
return channel.toObject();
}
@ -111,7 +111,6 @@ class VenueService extends SiteService {
updateOp.$set.slug = this.getChannelSlug(channelDefinition.url);
updateOp.$set.sortOrder = parseInt(channelDefinition.sortOrder || '0', 10);
const status = await this.updateChannelStatus(channel);
updateOp.$set.name = status.name;
updateOp.$set.description = status.description;
@ -126,7 +125,9 @@ class VenueService extends SiteService {
updateOp.$set['credentials.widgetKey'] = channelDefinition['credentials.widgetKey'].trim();
channel = await VenueChannel.findOneAndUpdate({ _id: channel._id }, updateOp, { new: true });
await this.updateChannelStatus(channel);
channel.currentStatus = await this.updateChannelStatus(channel);
return channel;
}
async getChannels (pagination, options) {
@ -146,7 +147,7 @@ class VenueService extends SiteService {
}
const channels = await q.populate(this.populateVenueChannel).lean();
for await (const channel of channels) {
for (const channel of channels) {
channel.currentStatus = await this.updateChannelStatus(channel);
}
return channels;
@ -202,20 +203,31 @@ class VenueService extends SiteService {
}
async updateChannelStatus (channel) {
const requestUrl = `https://${this.soapboxDomain}/channel/${channel.slug}/status`;
this.log.info('fetching Shing channel status', { slug: channel.slug, requestUrl });
const { logan: loganService } = this.dtp.services;
try {
const requestUrl = `https://${this.soapboxDomain}/channel/${channel.slug}/status`;
this.log.info('fetching Shing channel status', { slug: channel.slug, requestUrl });
const response = await fetch(requestUrl, { agent: this.httpsAgent });
if (!response.ok) {
throw new SiteError(500, `Failed to fetch channel status: ${response.statusText}`);
}
const response = await fetch(requestUrl, { agent: this.httpsAgent });
if (!response.ok) {
throw new SiteError(500, `Failed to fetch channel status: ${response.statusText}`);
}
const json = await response.json();
if (!json.success) {
throw new Error(`failed to fetch channel status: ${json.message}`);
}
const json = await response.json();
if (!json.success) {
throw new Error(`failed to fetch channel status: ${json.message}`);
return json.channel;
} catch (error) {
loganService.sendEvent(module.exports, {
level: 'error',
event: 'updateChannelStatus',
message: error.message,
data: { error },
});
return; // undefined
}
return json.channel;
}
getChannelSlug (channelUrl) {

@ -15,7 +15,10 @@ mixin renderVenueChannelListItem (channel, options)
.uk-width-expand.uk-text-truncate
+renderUserLink(channel.owner)
.uk-width-auto
if channel.currentStatus.status === 'live'
span.uk-text-success LIVE
if channel.currentStatus && channel.currentStatus.success
if channel.currentStatus.status === 'live'
span.uk-text-success LIVE
else
span= moment(channel.currentStatus.lastLive).fromNow()
else
span= moment(channel.currentStatus.lastLive).fromNow()
span ---
Loading…
Cancel
Save