'use strict';

var Boom = require('boom');

module.exports = function (elastic, config) {
  return function (request, reply) {
    var body = {
      query: {
        bool: { filter: { term: { 'identifier.value': request.params.idObject } } }
      }
    };
    var searchOpts = {
      index: 'smg',
      body: body
    };
    var jsonResult = {};

    elastic.search(searchOpts, function (error, result) {

      // no object found
      if (result.hits.total === 0) {
        jsonResult.found = false;
        jsonResult.error = 'Not Found';
        jsonResult.path = '';

        return reply(jsonResult).code(404);
      }

      jsonResult.found = true;
      jsonResult.error = null;
      jsonResult.path = '/objects/' + result.hits.hits[0]._id;

      // check for redirect query parameter
      if (request.query.redirect === 'true') {
        return reply.redirect(jsonResult.path);
      }

      return reply(jsonResult);
    });
  };
};

@@ -12,37 +12,8 @@
 ';%0A%0A
-var Boom = require('boom');%0A%0A
 modu
@@ -373,17 +373,16 @@
 sult) %7B%0A
-%0A
       //
@@ -509,16 +509,56 @@
 Found';%0A
+        jsonResult.searchError = error;%0A
         
@@ -664,16 +664,16 @@
 = true;%0A
-
       js
@@ -695,16 +695,54 @@
 = null;%0A
+      jsonResult.searchError = error;%0A
       js

attach elasticsearch error to the response, #757