changeset 940:861c080ef47b

handling httpStatus in WebService error messages
author Alain Mazy <alain@mazy.be>
date Fri, 02 Aug 2019 17:38:31 +0200
parents 9ba1e1198e73
children acc172f2b782
files Framework/Deprecated/Toolbox/BaseWebService.cpp Framework/Deprecated/Toolbox/IWebService.h Framework/Deprecated/Toolbox/OrthancApiClient.cpp Platforms/Generic/WebServiceCommandBase.cpp Platforms/Generic/WebServiceCommandBase.h Platforms/Generic/WebServiceDeleteCommand.cpp Platforms/Generic/WebServiceGetCommand.cpp Platforms/Generic/WebServicePostCommand.cpp Platforms/Wasm/WasmWebService.cpp Platforms/Wasm/WasmWebService.js Platforms/Wasm/wasm-application-runner.ts
diffstat 11 files changed, 25 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Deprecated/Toolbox/BaseWebService.cpp	Mon Jul 22 14:29:23 2019 +0200
+++ b/Framework/Deprecated/Toolbox/BaseWebService.cpp	Fri Aug 02 17:38:31 2019 +0200
@@ -75,6 +75,7 @@
       {
         // recreate a failure message with the user payload
         IWebService::HttpRequestErrorMessage failureMessage(message.GetUri(),
+                                                            message.GetHttpStatus(),
                                                             userPayload_.get());
 
         userFailureHandler_->Apply(failureMessage);
--- a/Framework/Deprecated/Toolbox/IWebService.h	Mon Jul 22 14:29:23 2019 +0200
+++ b/Framework/Deprecated/Toolbox/IWebService.h	Fri Aug 02 17:38:31 2019 +0200
@@ -106,12 +106,15 @@
     private:
       const std::string&              uri_;
       const Orthanc::IDynamicObject*  payload_;
+      Orthanc::HttpStatus             httpStatus_;
 
     public:
       HttpRequestErrorMessage(const std::string& uri,
+                              Orthanc::HttpStatus httpStatus,
                               const Orthanc::IDynamicObject* payload) :
         uri_(uri),
-        payload_(payload)
+        payload_(payload),
+        httpStatus_(httpStatus)
       {
       }
 
@@ -120,6 +123,11 @@
         return uri_;
       }
 
+      Orthanc::HttpStatus GetHttpStatus() const
+      {
+        return httpStatus_;
+      }
+
       bool HasPayload() const
       {
         return payload_ != NULL;
--- a/Framework/Deprecated/Toolbox/OrthancApiClient.cpp	Mon Jul 22 14:29:23 2019 +0200
+++ b/Framework/Deprecated/Toolbox/OrthancApiClient.cpp	Fri Aug 02 17:38:31 2019 +0200
@@ -79,7 +79,7 @@
       if (failureHandler_.get() != NULL)
       {
         failureHandler_->Apply(IWebService::HttpRequestErrorMessage
-                               (message.GetUri(), userPayload_.get()));
+                               (message.GetUri(), Orthanc::HttpStatus_None, userPayload_.get()));
       }
     }
     
@@ -176,7 +176,7 @@
       if (failureHandler_.get() != NULL)
       {
         failureHandler_->Apply(IWebService::HttpRequestErrorMessage
-                               (message.GetUri(), userPayload_.get()));
+                               (message.GetUri(), message.GetHttpStatus(), userPayload_.get()));
       }
     }
   };
--- a/Platforms/Generic/WebServiceCommandBase.cpp	Mon Jul 22 14:29:23 2019 +0200
+++ b/Platforms/Generic/WebServiceCommandBase.cpp	Fri Aug 02 17:38:31 2019 +0200
@@ -41,6 +41,8 @@
     url_(url),
     headers_(headers),
     payload_(payload),
+    success_(false),
+    httpStatus_(Orthanc::HttpStatus_None),
     context_(context),
     timeoutInSeconds_(timeoutInSeconds)
   {
@@ -62,7 +64,7 @@
     }
     else if (!success_ && failureCallback_.get() != NULL)
     {
-      IWebService::HttpRequestErrorMessage message(url_, payload_.get());
+      IWebService::HttpRequestErrorMessage message(url_, httpStatus_, payload_.get());
       failureCallback_->Apply(message);
     }
   }
--- a/Platforms/Generic/WebServiceCommandBase.h	Mon Jul 22 14:29:23 2019 +0200
+++ b/Platforms/Generic/WebServiceCommandBase.h	Fri Aug 02 17:38:31 2019 +0200
@@ -44,6 +44,7 @@
     IWebService::HttpHeaders                headers_;
     std::auto_ptr<Orthanc::IDynamicObject>  payload_;
     bool                                    success_;
+    Orthanc::HttpStatus                     httpStatus_;
     std::string                             answer_;
     IWebService::HttpHeaders                answerHeaders_;
     OrthancStone::NativeStoneApplicationContext&          context_;
--- a/Platforms/Generic/WebServiceDeleteCommand.cpp	Mon Jul 22 14:29:23 2019 +0200
+++ b/Platforms/Generic/WebServiceDeleteCommand.cpp	Fri Aug 02 17:38:31 2019 +0200
@@ -51,6 +51,7 @@
     }
 
     success_ = client.Apply(answer_, answerHeaders_);
+    httpStatus_ = client.GetLastStatus();
   }
 
 }
--- a/Platforms/Generic/WebServiceGetCommand.cpp	Mon Jul 22 14:29:23 2019 +0200
+++ b/Platforms/Generic/WebServiceGetCommand.cpp	Fri Aug 02 17:38:31 2019 +0200
@@ -53,6 +53,7 @@
     }
 
     success_ = client.Apply(answer_, answerHeaders_);
+    httpStatus_ = client.GetLastStatus();
   }
 
 }
--- a/Platforms/Generic/WebServicePostCommand.cpp	Mon Jul 22 14:29:23 2019 +0200
+++ b/Platforms/Generic/WebServicePostCommand.cpp	Fri Aug 02 17:38:31 2019 +0200
@@ -54,5 +54,6 @@
     }
 
     success_ = client.Apply(answer_, answerHeaders_);
+    httpStatus_ = client.GetLastStatus();
   }
 }
--- a/Platforms/Wasm/WasmWebService.cpp	Mon Jul 22 14:29:23 2019 +0200
+++ b/Platforms/Wasm/WasmWebService.cpp	Fri Aug 02 17:38:31 2019 +0200
@@ -43,12 +43,13 @@
 
   void EMSCRIPTEN_KEEPALIVE WasmWebService_NotifyError(void* failureCallable,
                                                        const char* uri,
+                                                       unsigned int httpStatus,
                                                        void* payload)
   {
     if (failureCallable != NULL)
     {
       reinterpret_cast<OrthancStone::MessageHandler<Deprecated::IWebService::HttpRequestErrorMessage>*>(failureCallable)->
-        Apply(Deprecated::IWebService::HttpRequestErrorMessage(uri, reinterpret_cast<Orthanc::IDynamicObject*>(payload)));
+        Apply(Deprecated::IWebService::HttpRequestErrorMessage(uri, static_cast<Orthanc::HttpStatus>(httpStatus), reinterpret_cast<Orthanc::IDynamicObject*>(payload)));
     }
   }
 
--- a/Platforms/Wasm/WasmWebService.js	Mon Jul 22 14:29:23 2019 +0200
+++ b/Platforms/Wasm/WasmWebService.js	Fri Aug 02 17:38:31 2019 +0200
@@ -27,7 +27,7 @@
           window.WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response),
                                        this.response.byteLength, headers, payload);
         } else {
-          window.WasmWebService_NotifyError(callableFailure, url_, payload);
+          window.WasmWebService_NotifyError(callableFailure, url_, xhr.status, payload);
         }
       }
     }
@@ -65,7 +65,7 @@
           window.WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response),
                                        this.response.byteLength, headers, payload);
         } else {
-          window.WasmWebService_NotifyError(callableFailure, url_, payload);
+          window.WasmWebService_NotifyError(callableFailure, url_, xhr.status, payload);
         }
       }
     }
@@ -97,7 +97,7 @@
           window.WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response),
                                        this.response.byteLength, headers, payload);
         } else {
-          window.WasmWebService_NotifyError(callableFailure, url_, payload);
+          window.WasmWebService_NotifyError(callableFailure, url_, xhr.status, payload);
         }
       }
     }
--- a/Platforms/Wasm/wasm-application-runner.ts	Mon Jul 22 14:29:23 2019 +0200
+++ b/Platforms/Wasm/wasm-application-runner.ts	Fri Aug 02 17:38:31 2019 +0200
@@ -121,7 +121,7 @@
 
     (<any> window).WasmWebService_NotifyCachedSuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyCachedSuccess', null, ['number']);
     (<any> window).WasmWebService_NotifySuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']);
-    (<any> window).WasmWebService_NotifyError = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']);
+    (<any> window).WasmWebService_NotifyError = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number', 'number']);
     (<any> window).WasmDelayedCallExecutor_ExecuteCallback = (<any> window).StoneFrameworkModule.cwrap('WasmDelayedCallExecutor_ExecuteCallback', null, ['number']);
     // no need to put this into the globals for it's only used in this very module
     WasmDoAnimation = (<any> window).StoneFrameworkModule.cwrap('WasmDoAnimation', null, []);