2
using System.Collections.Generic;
4
using ServiceStack.ServiceHost;
5
using ServiceStack.ServiceInterface.ServiceModel;
7
namespace ServiceStack.Common.Web
9
public class HttpError : Exception, IHttpError
11
public HttpError() : this(null) {}
13
public HttpError(string message)
14
: this(HttpStatusCode.InternalServerError, message) {}
16
public HttpError(HttpStatusCode statusCode, string errorCode)
17
: this(statusCode, errorCode, null) { }
19
public HttpError(int statusCode, string errorCode)
20
: this(statusCode, errorCode, null) { }
22
public HttpError(object responseDto, HttpStatusCode statusCode, string errorCode, string errorMessage)
23
: this(statusCode, errorCode, errorMessage)
25
this.Response = responseDto;
28
public HttpError(object responseDto, int statusCode, string errorCode, string errorMessage)
29
: this(statusCode, errorCode, errorMessage)
31
this.Response = responseDto;
34
public HttpError(HttpStatusCode statusCode, string errorCode, string errorMessage)
35
: this((int)statusCode, errorCode, errorMessage){}
37
public HttpError(int statusCode, string errorCode, string errorMessage)
38
: base(errorMessage ?? errorCode)
40
this.ErrorCode = errorCode;
41
this.Status = statusCode;
42
this.Headers = new Dictionary<string, string>();
43
this.StatusDescription = errorCode;
46
public HttpError(HttpStatusCode statusCode, Exception innerException)
47
: this(innerException.Message, innerException)
49
this.StatusCode = statusCode;
52
public HttpError(string message, Exception innerException) : base(message, innerException)
54
if (innerException != null)
56
this.ErrorCode = innerException.GetType().Name;
58
this.Headers = new Dictionary<string, string>();
61
public string ErrorCode { get; set; }
63
public string ContentType { get; set; }
65
public Dictionary<string, string> Headers { get; set; }
67
public int Status { get; set; }
69
public HttpStatusCode StatusCode
71
get { return (HttpStatusCode)Status; }
72
set { Status = (int)value; }
75
public string StatusDescription { get; set; }
77
public object Response { get; set; }
79
public IContentTypeWriter ResponseFilter { get; set; }
81
public IRequestContext RequestContext { get; set; }
83
public IDictionary<string, string> Options
85
get { return this.Headers; }
88
public ResponseStatus ResponseStatus
92
return this.Response.ToResponseStatus();
96
public List<ResponseError> GetFieldErrors()
98
var responseStatus = ResponseStatus;
99
if (responseStatus != null)
100
return responseStatus.Errors ?? new List<ResponseError>();
102
return new List<ResponseError>();
105
public static Exception NotFound(string message)
107
return new HttpError(HttpStatusCode.NotFound, message);
110
public static Exception Unauthorized(string message)
112
return new HttpError(HttpStatusCode.Unauthorized, message);
115
public static Exception Conflict(string message)
117
return new HttpError(HttpStatusCode.Conflict, message);
b'\\ No newline at end of file'