~ubuntu-branches/ubuntu/trusty/smuxi/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/ServiceStack/src/ServiceStack.Common/Web/HttpError.cs

  • Committer: Package Import Robot
  • Author(s): Mirco Bauer
  • Date: 2013-05-25 22:11:31 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20130525221131-nd2mc0kzubuwyx20
Tags: 0.8.11-1
* [22d13d5] Imported Upstream version 0.8.11
* [6d2b95a] Refreshed patches
* [89eb66e] Added ServiceStack libraries to smuxi-engine package
* [848ab10] Enable Campfire engine
* [c6dbdc7] Always build db4o for predictable build result
* [13ec489] Exclude OS X specific libraries from dh_clideps

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.Collections.Generic;
 
3
using System.Net;
 
4
using ServiceStack.ServiceHost;
 
5
using ServiceStack.ServiceInterface.ServiceModel;
 
6
 
 
7
namespace ServiceStack.Common.Web
 
8
{
 
9
    public class HttpError : Exception, IHttpError
 
10
    {
 
11
        public HttpError() : this(null) {}
 
12
 
 
13
        public HttpError(string message)
 
14
            : this(HttpStatusCode.InternalServerError, message) {}
 
15
 
 
16
        public HttpError(HttpStatusCode statusCode, string errorCode)
 
17
            : this(statusCode, errorCode, null) { }
 
18
 
 
19
        public HttpError(int statusCode, string errorCode)
 
20
            : this(statusCode, errorCode, null) { }
 
21
 
 
22
        public HttpError(object responseDto, HttpStatusCode statusCode, string errorCode, string errorMessage)
 
23
            : this(statusCode, errorCode, errorMessage)
 
24
        {
 
25
            this.Response = responseDto;
 
26
        }
 
27
 
 
28
        public HttpError(object responseDto, int statusCode, string errorCode, string errorMessage)
 
29
            : this(statusCode, errorCode, errorMessage)
 
30
        {
 
31
            this.Response = responseDto;
 
32
        }
 
33
 
 
34
        public HttpError(HttpStatusCode statusCode, string errorCode, string errorMessage)
 
35
            : this((int)statusCode, errorCode, errorMessage){}
 
36
 
 
37
        public HttpError(int statusCode, string errorCode, string errorMessage)
 
38
            : base(errorMessage ?? errorCode)
 
39
        {
 
40
            this.ErrorCode = errorCode;
 
41
            this.Status = statusCode;
 
42
            this.Headers = new Dictionary<string, string>();
 
43
            this.StatusDescription = errorCode;
 
44
        }
 
45
 
 
46
        public HttpError(HttpStatusCode statusCode, Exception innerException)
 
47
            : this(innerException.Message, innerException)
 
48
        {
 
49
            this.StatusCode = statusCode;
 
50
        }
 
51
 
 
52
        public HttpError(string message, Exception innerException) : base(message, innerException)
 
53
        {
 
54
            if (innerException != null)
 
55
            {
 
56
                this.ErrorCode = innerException.GetType().Name;
 
57
            }
 
58
            this.Headers = new Dictionary<string, string>();                    
 
59
        }
 
60
 
 
61
        public string ErrorCode { get; set; }
 
62
 
 
63
        public string ContentType { get; set; }
 
64
 
 
65
        public Dictionary<string, string> Headers { get; set; }
 
66
        
 
67
        public int Status { get; set; }
 
68
 
 
69
        public HttpStatusCode StatusCode
 
70
        {
 
71
            get { return (HttpStatusCode)Status; }
 
72
            set { Status = (int)value; }
 
73
        }
 
74
 
 
75
        public string StatusDescription { get; set; }
 
76
 
 
77
        public object Response { get; set; }
 
78
 
 
79
        public IContentTypeWriter ResponseFilter { get; set; }
 
80
        
 
81
        public IRequestContext RequestContext { get; set; }
 
82
 
 
83
        public IDictionary<string, string> Options
 
84
        {
 
85
            get { return this.Headers; }
 
86
        }
 
87
 
 
88
        public ResponseStatus ResponseStatus
 
89
        {
 
90
            get
 
91
            {
 
92
                return this.Response.ToResponseStatus();
 
93
            }
 
94
        }
 
95
 
 
96
        public List<ResponseError> GetFieldErrors()
 
97
        {
 
98
            var responseStatus = ResponseStatus;
 
99
            if (responseStatus != null)
 
100
                return responseStatus.Errors ?? new List<ResponseError>();
 
101
            
 
102
            return new List<ResponseError>();
 
103
        }
 
104
 
 
105
        public static Exception NotFound(string message)
 
106
        {
 
107
            return new HttpError(HttpStatusCode.NotFound, message);
 
108
        }
 
109
 
 
110
        public static Exception Unauthorized(string message)
 
111
        {
 
112
            return new HttpError(HttpStatusCode.Unauthorized, message);
 
113
        }
 
114
 
 
115
        public static Exception Conflict(string message)
 
116
        {
 
117
            return new HttpError(HttpStatusCode.Conflict, message);
 
118
        }
 
119
    }
 
120
}
 
 
b'\\ No newline at end of file'