diff Core/Enumerations.cpp @ 1576:de54c19fc44d

refactoring OrthancException
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Aug 2015 14:48:06 +0200
parents f8aae45011c9
children 7aac0cddd42e
line wrap: on
line diff
--- a/Core/Enumerations.cpp	Tue Aug 25 14:00:57 2015 +0200
+++ b/Core/Enumerations.cpp	Tue Aug 25 14:48:06 2015 +0200
@@ -919,4 +919,39 @@
         throw OrthancException(ErrorCode_ParameterOutOfRange);
     }
   }
+
+
+  HttpStatus ConvertErrorCodeToHttpStatus(ErrorCode error)
+  {
+    switch (error)
+    {
+      case ErrorCode_Success:
+      {
+        return HttpStatus_200_Ok;
+      }
+
+      case ErrorCode_InexistentFile:
+      case ErrorCode_InexistentItem:
+      case ErrorCode_InexistentTag:
+      case ErrorCode_UnknownResource:
+      {
+        return HttpStatus_404_NotFound;
+      }
+
+      case ErrorCode_BadFileFormat:
+      case ErrorCode_BadParameterType:
+      case ErrorCode_BadRequest:
+      case ErrorCode_ParameterOutOfRange:
+      case ErrorCode_UriSyntax:
+      {
+        return HttpStatus_400_BadRequest;
+        break;
+      }
+
+      default:
+      {
+        return HttpStatus_500_InternalServerError;
+      }
+    }
+  }
 }