/**
 * Serve page not found html.
 * @function serverside.middleware.definePageNotFoundMiddleware
 * @param {object} context - Server context object.
 * @returns {function} - A page not found middleware.
 * @author Taka Okunishi
 *
 */
module.exports = function (context) {
    return function (req, res, next) {
        if (!req.lang) throw new Error('Method missing: req.lang');
        if (!res.pageNotFound) throw new Error('Method missing: res.pageNotFound');
        var lang = req.lang();
        res.pageNotFound(lang, function (err) {
            if (err) {
                next(err);
            }
        });
    };
};