UNPKG

gpii-universal

Version:

Cross platform, core components of the GPII personalization infrastructure.

48 lines (39 loc) 1.42 kB
/*! GPII Preferences Server Ready Check Handler Copyright 2018 OCAD University Licensed under the New BSD license. You may not use this file except in compliance with this License. You may obtain a copy of the License at https://github.com/GPII/universal/blob/master/LICENSE.txt */ "use strict"; var fluid = require("infusion"), gpii = fluid.registerNamespace("gpii"); fluid.defaults("gpii.preferencesServer.ready.handler", { gradeNames: ["kettle.request.http"], invokers: { handleRequest: { funcName: "gpii.preferencesServer.ready.handler.getPreferences", args: ["{preferencesServer}", "{that}"] } } }); gpii.preferencesServer.ready.handler.reportError = function (request) { request.events.onError.fire({ isError: true, message: "Problem with the database connection", statusCode: 503 }); }; gpii.preferencesServer.ready.handler.getPreferences = function (preferencesServer, request) { var isLivePromise = preferencesServer.preferencesService.isLive(); isLivePromise.then(function (value) { // onResolve if (value.isReady) { request.events.onSuccess.fire(value); } else { gpii.preferencesServer.ready.handler.reportError(request); } }, function () { // onReject gpii.preferencesServer.ready.handler.reportError(request); }); };