Skip to content

Commit

Permalink
269 - Log warning for deprecated transitions (#338)
Browse files Browse the repository at this point in the history
Ticket: #269
This commit will:
* Add a feature to log warning when deprecated transitions are activated when uploading app settings.
* Skip 404 errors when requesting deprecated messages
  • Loading branch information
latin-panda authored Sep 14, 2020
1 parent 3e1be8e commit 395ddcb
Showing 1 changed file with 52 additions and 6 deletions.
58 changes: 52 additions & 6 deletions src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,43 @@ const request = require('request-promise-native');

const archivingApi = require('./archiving-api');
const environment = require('./environment');
const log = require('../lib/log');

const logDeprecatedTransitions = (settings) => {
const appSettings = JSON.parse(settings);

if (!appSettings.transitions || !Object.keys(appSettings.transitions).length) {
return;
}

const uri = `${environment.instanceUrl}/api/v1/settings/deprecated-transitions`;

return request({ uri, method: 'GET', json: true})
.then(transitions => {
(transitions || []).forEach(transition => {
const transitionSetting = appSettings.transitions[transition.name];
const disabled = transitionSetting && transitionSetting.disable;

if (transitionSetting && !disabled) {
log.warn(transition.deprecationMessage);
}
});
})
.catch(error => {
if (error.statusCode !== 404) {
throw error;
}
});
};

const updateAppSettings = (settings) => {
return request.put({
method: 'PUT',
url: `${environment.apiUrl}/_design/medic/_rewrite/update_settings/medic?replace=1`,
headers: {'Content-Type': 'application/json'},
body: settings,
});
};

const api = {
getAppSettings: () => {
Expand All @@ -17,12 +54,21 @@ const api = {
});
},

updateAppSettings: (content) => request.put({
method: 'PUT',
url: `${environment.apiUrl}/_design/medic/_rewrite/update_settings/medic?replace=1`,
headers: { 'Content-Type':'application/json' },
body: content,
}),
updateAppSettings: (content) => {
return Promise.allSettled([
updateAppSettings(content),
logDeprecatedTransitions(content)
]).then(([updateSettingsResp, logTransitionResp]) => {
if (logTransitionResp.status === 'rejected') {
// Log error and continue with the work, this isn't a blocking task.
log.error('Error in logging deprecated transitions:', logTransitionResp.reason);
}
if (updateSettingsResp.status === 'rejected') {
throw updateSettingsResp.reason;
}
return updateSettingsResp.value;
});
},

createUser(userData) {
return request({
Expand Down

0 comments on commit 395ddcb

Please sign in to comment.