Mercurial > hg > orthanc-stone
comparison Framework/Oracle/WebAssemblyOracle.cpp @ 995:9893fa8cd7a6
send error message for HTTP fetching in wasm
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 14 Sep 2019 17:27:41 +0200 |
parents | a9f5d0742e22 |
children | 727f2007ca23 |
comparison
equal
deleted
inserted
replaced
994:1f74bc3459ba | 995:9893fa8cd7a6 |
---|---|
20 | 20 |
21 | 21 |
22 #include "WebAssemblyOracle.h" | 22 #include "WebAssemblyOracle.h" |
23 | 23 |
24 #include "SleepOracleCommand.h" | 24 #include "SleepOracleCommand.h" |
25 #include "OracleCommandExceptionMessage.h" | |
25 | 26 |
26 #include <Core/OrthancException.h> | 27 #include <Core/OrthancException.h> |
27 #include <Core/Toolbox.h> | 28 #include <Core/Toolbox.h> |
28 | 29 |
29 #include <emscripten.h> | 30 #include <emscripten.h> |
350 } | 351 } |
351 | 352 |
352 static void FailureCallback(emscripten_fetch_t *fetch) | 353 static void FailureCallback(emscripten_fetch_t *fetch) |
353 { | 354 { |
354 std::auto_ptr<FetchContext> context(reinterpret_cast<FetchContext*>(fetch->userData)); | 355 std::auto_ptr<FetchContext> context(reinterpret_cast<FetchContext*>(fetch->userData)); |
356 | |
357 { | |
358 const size_t kEmscriptenStatusTextSize = sizeof(emscripten_fetch_t::statusText); | |
359 char message[kEmscriptenStatusTextSize + 1]; | |
360 memcpy(message, fetch->statusText, kEmscriptenStatusTextSize); | |
361 message[kEmscriptenStatusTextSize] = 0; | |
362 | |
363 LOG(ERROR) << "Fetching " << fetch->url | |
364 << " failed, HTTP failure status code: " << fetch->status | |
365 << " | statusText = " << message | |
366 << " | numBytes = " << fetch->numBytes | |
367 << " | totalBytes = " << fetch->totalBytes | |
368 << " | readyState = " << fetch->readyState; | |
369 } | |
370 | |
371 { | |
372 OracleCommandExceptionMessage message | |
373 (context->GetCommand(), Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol)); | |
374 context->EmitMessage(message); | |
375 } | |
355 | 376 |
356 const size_t kEmscriptenStatusTextSize = sizeof(emscripten_fetch_t::statusText); | |
357 char message[kEmscriptenStatusTextSize + 1]; | |
358 memcpy(message, fetch->statusText, kEmscriptenStatusTextSize); | |
359 message[kEmscriptenStatusTextSize] = 0; | |
360 | |
361 LOG(ERROR) << "Fetching " << fetch->url | |
362 << " failed, HTTP failure status code: " << fetch->status | |
363 << " | statusText = " << message | |
364 << " | numBytes = " << fetch->numBytes | |
365 << " | totalBytes = " << fetch->totalBytes | |
366 << " | readyState = " << fetch->readyState; | |
367 | |
368 /** | 377 /** |
369 * TODO - The following code leads to an infinite recursion, at | 378 * TODO - The following code leads to an infinite recursion, at |
370 * least with Firefox running on incognito mode => WHY? | 379 * least with Firefox running on incognito mode => WHY? |
371 **/ | 380 **/ |
372 emscripten_fetch_close(fetch); // Also free data on failure. | 381 emscripten_fetch_close(fetch); // Also free data on failure. |