Mercurial > hg > orthanc
comparison OrthancServer/main.cpp @ 1649:8040d56cb0b3
New function "OrthancPluginRegisterErrorCode()" to declare custom error codes
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 25 Sep 2015 16:24:13 +0200 |
parents | 1558b3226b18 |
children | 9f34ebfaf2c9 |
comparison
equal
deleted
inserted
replaced
1648:a0a4fa28624c | 1649:8040d56cb0b3 |
---|---|
325 virtual void Format(HttpOutput& output, | 325 virtual void Format(HttpOutput& output, |
326 const OrthancException& exception, | 326 const OrthancException& exception, |
327 HttpMethod method, | 327 HttpMethod method, |
328 const char* uri) | 328 const char* uri) |
329 { | 329 { |
330 if (!describeErrors_) | |
331 { | |
332 output.SendStatus(exception.GetHttpStatus()); | |
333 return; | |
334 } | |
335 | |
336 Json::Value message = Json::objectValue; | 330 Json::Value message = Json::objectValue; |
337 message["Method"] = EnumerationToString(method); | |
338 message["Uri"] = uri; | |
339 | |
340 ErrorCode errorCode = exception.GetErrorCode(); | 331 ErrorCode errorCode = exception.GetErrorCode(); |
341 HttpStatus httpStatus = exception.GetHttpStatus(); | 332 HttpStatus httpStatus = exception.GetHttpStatus(); |
342 | 333 |
343 bool isPlugin = false; | 334 { |
335 bool isPlugin = false; | |
344 | 336 |
345 #if ORTHANC_PLUGINS_ENABLED == 1 | 337 #if ORTHANC_PLUGINS_ENABLED == 1 |
346 if (plugins_ != NULL && | 338 if (plugins_ != NULL && |
347 plugins_->GetErrorDictionary().Format(message, httpStatus, exception)) | 339 plugins_->GetErrorDictionary().Format(message, httpStatus, exception)) |
348 { | 340 { |
349 errorCode = ErrorCode_Plugin; | 341 LOG(ERROR) << "Error code " << message["PluginCode"].asInt() << " inside plugin \"" |
350 isPlugin = true; | 342 << message["PluginName"].asString() << "\": " << message["Message"].asString(); |
351 } | 343 errorCode = ErrorCode_Plugin; |
344 isPlugin = true; | |
345 } | |
352 #endif | 346 #endif |
353 | 347 |
354 if (!isPlugin) | 348 if (!isPlugin) |
355 { | 349 { |
356 message["Message"] = exception.What(); | 350 LOG(ERROR) << "Exception in the HTTP handler: " << exception.What(); |
357 } | 351 message["Message"] = exception.What(); |
358 | 352 } |
359 message["HttpError"] = EnumerationToString(httpStatus); | 353 } |
360 message["HttpStatus"] = httpStatus; | 354 |
361 message["OrthancError"] = EnumerationToString(errorCode); | 355 if (!describeErrors_) |
362 message["OrthancStatus"] = errorCode; | 356 { |
363 | 357 output.SendStatus(httpStatus); |
364 std::string info = message.toStyledString(); | 358 } |
365 output.SendStatus(httpStatus, info); | 359 else |
360 { | |
361 message["Method"] = EnumerationToString(method); | |
362 message["Uri"] = uri; | |
363 message["HttpError"] = EnumerationToString(httpStatus); | |
364 message["HttpStatus"] = httpStatus; | |
365 message["OrthancError"] = EnumerationToString(errorCode); | |
366 message["OrthancStatus"] = errorCode; | |
367 | |
368 std::string info = message.toStyledString(); | |
369 output.SendStatus(httpStatus, info); | |
370 } | |
366 } | 371 } |
367 }; | 372 }; |
368 | 373 |
369 | 374 |
370 | 375 |