From bbf4e1c41339738ce2563c3c7ae427ba4997bf3f Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 6 Mar 2019 23:23:50 +0900 Subject: [PATCH] Add fallback for broken db --- src/models/app.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/models/app.ts b/src/models/app.ts index 5c8d2cbd5..45d50bccd 100644 --- a/src/models/app.ts +++ b/src/models/app.ts @@ -4,6 +4,7 @@ import AccessToken from './access-token'; import db from '../db/mongodb'; import isObjectId from '../misc/is-objectid'; import config from '../config'; +import { dbLogger } from '../db/logger'; const App = db.get('apps'); App.createIndex('secret'); @@ -66,6 +67,12 @@ export const pack = ( } } + // (データベースの欠損などで)アプリがデータベース上に見つからなかったとき + if (_app == null) { + dbLogger.warn(`[DAMAGED DB] (missing) pkg: app :: ${app}`); + return null; + } + // Rename _id to id _app.id = _app._id; delete _app._id;