changeset 1438:af112b7d9cba

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 01 Jul 2015 09:56:41 +0200
parents 02f5a3f5c0a0
children 354640db5a7f
files Core/HttpServer/MongooseServer.cpp Core/Lua/LuaContext.cpp
diffstat 2 files changed, 26 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpServer/MongooseServer.cpp	Tue Jun 30 18:41:33 2015 +0200
+++ b/Core/HttpServer/MongooseServer.cpp	Wed Jul 01 09:56:41 2015 +0200
@@ -696,21 +696,29 @@
         // Using this candidate handler results in an exception
         LOG(ERROR) << "Exception in the HTTP handler: " << e.What();
 
-        switch (e.GetErrorCode())
+        try
         {
-          case ErrorCode_InexistentFile:
-          case ErrorCode_InexistentItem:
-          case ErrorCode_UnknownResource:
-            output.SendStatus(HttpStatus_404_NotFound);
-            break;
+          switch (e.GetErrorCode())
+          {
+            case ErrorCode_InexistentFile:
+            case ErrorCode_InexistentItem:
+            case ErrorCode_UnknownResource:
+              output.SendStatus(HttpStatus_404_NotFound);
+              break;
 
-          case ErrorCode_BadRequest:
-          case ErrorCode_UriSyntax:
-            output.SendStatus(HttpStatus_400_BadRequest);
-            break;
+            case ErrorCode_BadRequest:
+            case ErrorCode_UriSyntax:
+              output.SendStatus(HttpStatus_400_BadRequest);
+              break;
 
-          default:
-            output.SendStatus(HttpStatus_500_InternalServerError);
+            default:
+              output.SendStatus(HttpStatus_500_InternalServerError);
+          }
+        }
+        catch (OrthancException&)
+        {
+          // An exception here reflects the fact that an exception was
+          // triggered after the status code was sent by the HTTP handler.
         }
 
         return;
--- a/Core/Lua/LuaContext.cpp	Tue Jun 30 18:41:33 2015 +0200
+++ b/Core/Lua/LuaContext.cpp	Wed Jul 01 09:56:41 2015 +0200
@@ -172,7 +172,7 @@
     if (nArgs != 1 || !lua_isstring(state, 1))  // URL
     {
       LOG(ERROR) << "Lua: Bad parameters to HttpGet()";
-      lua_pushstring(state, "ERROR");
+      lua_pushnil(state);
       return 1;
     }
 
@@ -185,7 +185,7 @@
     if (!that.AnswerHttpQuery(state))
     {
       LOG(ERROR) << "Lua: Error in HttpGet() for URL " << url;
-      lua_pushstring(state, "ERROR");
+      lua_pushnil(state);
     }
 
     return 1;
@@ -204,7 +204,7 @@
         (nArgs >= 2 && !lua_isstring(state, 2)))  // Body data
     {
       LOG(ERROR) << "Lua: Bad parameters to HttpPost() or HttpPut()";
-      lua_pushstring(state, "ERROR");
+      lua_pushnil(state);
       return 1;
     }
 
@@ -226,7 +226,7 @@
     if (!that.AnswerHttpQuery(state))
     {
       LOG(ERROR) << "Lua: Error in HttpPost() or HttpPut() for URL " << url;
-      lua_pushstring(state, "ERROR");
+      lua_pushnil(state);
     }
 
     return 1;
@@ -254,7 +254,7 @@
     if (nArgs != 1 || !lua_isstring(state, 1))  // URL
     {
       LOG(ERROR) << "Lua: Bad parameters to HttpDelete()";
-      lua_pushstring(state, "ERROR");
+      lua_pushnil(state);
       return 1;
     }
 
@@ -268,7 +268,7 @@
     if (!that.httpClient_.Apply(s))
     {
       LOG(ERROR) << "Lua: Error in HttpDelete() for URL " << url;
-      lua_pushstring(state, "ERROR");
+      lua_pushnil(state);
     }
     else
     {