/**
 * To retrieve the picture of the day for a given date.
 */

'use strict';

const BBPromise = require('bluebird');
const dateUtil = require('../dateUtil');
const sUtil = require('../util');
const imageinfo = require('../imageinfo');
const HTTPError = sUtil.HTTPError;

/**
 * Get imageinfo data for featured image (Picture of the day)
 * @param  {Object} app      App object
 * @param  {Object} req      req Server request
 * @param  {Object} siteinfo Site info object
 * @return {Object}          featured image response
 */
function promise(req, siteinfo) {
    const aggregated = !!req.query.aggregated;

    if (!dateUtil.validate(dateUtil.hyphenDelimitedDateString(req))) {
        if (aggregated) {
            return BBPromise.resolve({ meta: {} });
        }
        dateUtil.throwDateError();
    }

    return imageinfo.requestPictureOfTheDay(req, dateUtil.getRequestedDate(req), siteinfo)
    .catch((err) => {
        if (aggregated && err.status === 504) {
            return BBPromise.resolve({ meta: {} });
        }
        throw err;
    });
}

module.exports = {
    promise,
};

/**
 * To retrieve the picture of the day for a given date.
 */

'use strict';

const BBPromise = require('bluebird');
const dateUtil = require('../dateUtil');
const imageinfo = require('../imageinfo');

/**
 * Get imageinfo data for featured image (Picture of the day)
 * @param  {Object} req      req Server request
 * @param  {Object} siteinfo Site info object
 * @return {Object}          featured image response
 */
function promise(req, siteinfo) {
    const aggregated = !!req.query.aggregated;

    if (!dateUtil.validate(dateUtil.hyphenDelimitedDateString(req))) {
        if (aggregated) {
            return BBPromise.resolve({ meta: {} });
        }
        dateUtil.throwDateError();
    }

    return imageinfo.requestPictureOfTheDay(req, dateUtil.getRequestedDate(req), siteinfo)
    .catch((err) => {
        if (aggregated) {
            return BBPromise.resolve({ meta: {} });
        }
        throw err;
    });
}

module.exports = {
    promise,
};

Stop limiting error handling for aggregated requests
Featured-image: Stop limiting error handling for aggregated requests

Several feed endpoints have graceful error handling for aggregated
requests, meant to allow RESTBase to gracefully omit featured feed
content where the underlying content is not found as expected.

For the featured image endpoint, this is limited to 504 responses for
some reason. That doesn't seem necessary or desirable, so this removes
it.

Also removed some unused imports.

Change-Id: Id5282325b51ae2eb3514a2ee56afbb7c755c4aff
