/// <summary> /// Serializes the 'error' and 'innererror' properties of the JSON document returned by the Serialize() method. /// </summary> /// <param name="httpInternalServerError">The HttpInternalServerError object to serialize.</param> /// <returns>The 'error' or 'innererror' property of the JSON document.</returns> protected JObject SerializeError(HttpInternalServerError httpInternalServerError) { var returnDocument = new JObject(); returnDocument.Add(codePropertyName, httpInternalServerError.Code); returnDocument.Add(messagePropertyName, httpInternalServerError.Message); if (httpInternalServerError.Target != null) { returnDocument.Add(targetPropertyName, httpInternalServerError.Target); } var attributesJson = new JArray(); foreach (Tuple <String, String> currentAttribute in httpInternalServerError.Attributes) { var currentAttributeJson = new JObject(); currentAttributeJson.Add(namePropertyName, currentAttribute.Item1); currentAttributeJson.Add(valuePropertyName, currentAttribute.Item2); attributesJson.Add(currentAttributeJson); } if (attributesJson.Count > 0) { returnDocument.Add(attributesPropertyName, attributesJson); } if (httpInternalServerError.InnerError != null) { returnDocument.Add(innerErrorPropertyName, SerializeError(httpInternalServerError.InnerError)); } return(returnDocument); }
/// <summary> /// Initialises a new instance of the TryML.Utilities.ExceptionHandling.HttpInternalServerError class. /// </summary> /// <param name="code">An internal code representing the error.</param> /// <param name="message">A description of the error.</param> /// <param name="target">The target of the error.</param> /// <param name="attributes">A collection of key/value pairs which give additional details of the error.</param> /// <param name="innerError">The error which caused this error.</param> public HttpInternalServerError(String code, String message, String target, List <Tuple <String, String> > attributes, HttpInternalServerError innerError) : this(code, message) { this.target = target; this.attributes = attributes; this.innerError = innerError; }
/// <summary> /// Serializes the specified HttpInternalServerError to a JSON document. /// </summary> /// <param name="httpInternalServerError">The HttpInternalServerError object to serialize.</param> /// <returns>A JSON document representing the HttpInternalServerError.</returns> public JObject Serialize(HttpInternalServerError httpInternalServerError) { var returnDocument = new JObject(); returnDocument.Add(errorPropertyName, SerializeError(httpInternalServerError)); return(returnDocument); }
/// <summary> /// Initialises a new instance of the TryML.Utilities.ExceptionHandling.HttpInternalServerError class. /// </summary> /// <param name="code">An internal code representing the error.</param> /// <param name="message">A description of the error.</param> public HttpInternalServerError(String code, String message) { // Ordinarily would have exception handlers here for null or whitespace 'code' and 'message' parameters... // However since this instances of this class will likely be created as part of exception handling code, we don't want to throw further exceptions and risk hiding/losing the original exception details. this.code = code; this.message = message; target = null; attributes = new List <Tuple <String, String> >(); innerError = null; }
/// <summary> /// Converts the specified exception to an HttpInternalServerError, recursively converting any inner exceptions. /// </summary> /// <param name="exception">The exception to convert.</param> /// <returns>The converted exception.</returns> protected HttpInternalServerError ConvertExceptionRecurse(Exception exception) { // Recursively call for any inner exceptions HttpInternalServerError innerError = null; if (exception.InnerException != null) { innerError = ConvertExceptionRecurse(exception.InnerException); } // Convert the exception using a matching function from the type to conversion function map HttpInternalServerError returnError = ConvertException(exception); if (innerError != null) { returnError.InnerError = innerError; } return(returnError); }
/// <summary> /// Initialises a new instance of the TryML.Utilities.ExceptionHandling.HttpInternalServerError class. /// </summary> /// <param name="code">An internal code representing the error.</param> /// <param name="message">A description of the error.</param> /// <param name="target">The target of the error.</param> /// <param name="innerError">The error which caused this error.</param> public HttpInternalServerError(String code, String message, String target, HttpInternalServerError innerError) : this(code, message) { this.target = target; this.innerError = innerError; }