1 module xmlrpcc.error; 2 3 import std.exception; 4 import std.stdio; 5 import std.variant : Variant; 6 import std.format : format; 7 8 import xmlrpcc.data; 9 10 /** 11 * Root type for all XML-RPC exceptions 12 */ 13 class XmlRpcException : Exception { 14 this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) { 15 super(msg, file, line, next); 16 } 17 } 18 19 /** 20 * Client throws this exception if the remote method returns XML-RPC Fault Response. 21 * Server catches this exception and converts it into XML-RPC Fault Response. 22 */ 23 class MethodFaultException : XmlRpcException { 24 package this(Variant value, string message) { 25 this.value = value; 26 super(message); 27 } 28 29 @trusted package this(Variant value) { 30 this(value, format("XMLRPC method failure: %s", value.toString())); 31 } 32 33 this(string faultString, int faultCode) { 34 this(makeFaultValue(faultString, faultCode)); 35 } 36 37 Variant value; 38 } 39 40 /** 41 * Fault Code Interoperability constants 42 * http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php 43 */ 44 enum FciFaultCodes : int { 45 parseErrorNotWellFormed = -32_700, 46 parseErrorUnsupportedEncoding = -32_701, 47 parseErrorInvalidCharacter = -32_702, 48 49 serverErrorInvalidXmlRpc = -32_600, 50 serverErrorMethodNotFound = -32_601, 51 serverErrorInvalidMethodParams = -32_602, 52 serverErrorInternalXmlRpcError = -32_603, 53 54 applicationError = -32_500, 55 systemError = -32_400, 56 transportError = -32_300 57 } 58 59 package Variant makeFaultValue(string faultString, int faultCode) { 60 return Variant(["faultCode" : Variant(faultCode), "faultString" : Variant(faultString)]); 61 }