[Groonga-commit] groonga/express-droonga at f478583 [master] Change definition style of API commands around HTTP

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Aug 1 13:54:53 JST 2013


YUKI Hiroshi	2013-08-01 13:54:53 +0900 (Thu, 01 Aug 2013)

  New Revision: f478583545dce7af95cfd4f93ae1f5baf68798cf
  https://github.com/groonga/express-droonga/commit/f478583545dce7af95cfd4f93ae1f5baf68798cf

  Message:
    Change definition style of API commands around HTTP

  Modified files:
    lib/adapter/http.js

  Modified: lib/adapter/http.js (+15 -12)
===================================================================
--- lib/adapter/http.js    2013-08-01 13:49:27 +0900 (998bdd7)
+++ lib/adapter/http.js    2013-08-01 13:54:53 +0900 (bd738bf)
@@ -17,8 +17,6 @@ function createHandler(params) {
     debug('adapter.http.createHandler.handle');
 
     var result = definition.requestConverter(commandName, request);
-    var messageType = result[0];
-    var body = result[1];
     var timeout = body.timeout || null;
     var options = { timeout: timeout };
     var callback = function(error, envelope) {
@@ -30,20 +28,25 @@ function createHandler(params) {
         } else {
           debug('adapter.rest.createHandler.handle.response.success');
           var body = envelope.body;
-          if (definition.responseConverter) {
-            var result = definition.responseConverter(commandName, body);
-            body = result[1];
+          if (definition.onResponse) {
+            definition.onResponse(body, response);
+          } else {
+            response.jsonp(body, 200);
           }
-          response.jsonp(body, 200);
         }
       }
 
-    connection.emitMessage(
-      messageType,
-      body,
-      callback,
-      options
-    );
+    var wrappedConection = new wrapper.DroongaProtocolConnectionWrapper(connection, callback, options);
+    if (definition.onRequest) {
+      try {
+        definition.onRequest(request, wrappedConection);
+      } catch(error) {
+        wrappedConection.destroy();
+        response.jsonp(error, 500);
+      }
+    } else {
+      wrappedConection.emit(commandName, request.query);
+    }
   });
 }
 exports.createHandler = createHandler;
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index