mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Improved code safety in update check's check method
refs https://github.com/TryGhost/Team/issues/754 - The api call can also generate an error which would bubble up to a client. This is not a good design if the client has to know to handle internal errors of the module - By having try block wrap around whole block it makes the error handling behave the same way throughout the check process
This commit is contained in:
parent
d45ef018fe
commit
9e5fe475c8
1 changed files with 10 additions and 10 deletions
|
@ -339,17 +339,17 @@ class UpdateCheckService {
|
|||
* @returns {Promise}
|
||||
*/
|
||||
async check() {
|
||||
const result = await this.api.settings.read(_.extend({key: 'next_update_check'}, internal));
|
||||
|
||||
const nextUpdateCheck = result.settings[0];
|
||||
|
||||
// CASE: Next update check should happen now?
|
||||
// @NOTE: You can skip this check by adding a config value. This is helpful for developing.
|
||||
if (!this.config.forceUpdate && nextUpdateCheck && nextUpdateCheck.value && nextUpdateCheck.value > moment().unix()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await this.api.settings.read(_.extend({key: 'next_update_check'}, internal));
|
||||
|
||||
const nextUpdateCheck = result.settings[0];
|
||||
|
||||
// CASE: Next update check should happen now?
|
||||
// @NOTE: You can skip this check by adding a config value. This is helpful for developing.
|
||||
if (!this.config.forceUpdate && nextUpdateCheck && nextUpdateCheck.value && nextUpdateCheck.value > moment().unix()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await this.updateCheckRequest();
|
||||
|
||||
return await this.updateCheckResponse(response);
|
||||
|
|
Loading…
Add table
Reference in a new issue