1- using System ;
1+ #region License
2+ // https://github.com/ofpinewood/http-exceptions/blob/main/LICENSE
3+ //
4+ // The latest version of this file can be found at https://github.com/ofpinewood/http-exceptions/blob/main/src/Opw.HttpExceptions/ResponseStatusCodeLink.cs
5+ #endregion
6+
7+
8+ using System ;
29
310namespace PowerUtils . Net . Constants
411{
5- // Reference: https://github.com/ofpinewood/http-exceptions/blob/main/src/Opw.HttpExceptions/ResponseStatusCodeLink.cs
12+ // Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#information_responses
613
714 /// <summary>
815 /// Status code information links to https://tools.ietf.org/html/rfc7231.
916 /// </summary>
1017 public static class StatusCodeLink
1118 {
12- private const string BASE_URL = "https://tools.ietf.org/" ;
19+ private const string BASE_URL = "https://tools.ietf.org/html/ " ;
1320
14- public const string STATUS_CODES = BASE_URL + "html/rfc7231#section-6" ;
21+ public const string STATUS_CODES = BASE_URL + "rfc7231#section-6" ;
22+
23+ public const string BAD_REQUEST = BASE_URL + "rfc7231#section-6.5.1" ;
24+ public const string UNAUTHORIZED = BASE_URL + "rfc7235#section-3.1" ;
25+ public const string PAYMENT_REQUIRED = BASE_URL + "rfc7231#section-6.5.2" ;
26+ public const string FORBIDDEN = BASE_URL + "rfc7231#section-6.5.3" ;
27+ public const string NOT_FOUND = BASE_URL + "rfc7231#section-6.5.4" ;
28+ public const string METHOD_NOT_ALLOWED = BASE_URL + "rfc7231#section-6.5.5" ;
29+ public const string NOT_ACCEPTABLE = BASE_URL + "rfc7231#section-6.5.6" ;
30+ public const string PROXY_AUTHENTICATION_REQUIRED = BASE_URL + "rfc7235#section-3.2" ;
31+ public const string REQUEST_TIMEOUT = BASE_URL + "rfc7231#section-6.5.7" ;
32+ public const string CONFLICT = BASE_URL + "rfc7231#section-6.5.8" ;
33+ public const string GONE = BASE_URL + "rfc7231#section-6.5.9" ;
34+ public const string LENGTH_REQUIRED = BASE_URL + "rfc7231#section-6.5.10" ;
35+ public const string PRECONDITION_FAILED = BASE_URL + "rfc7232#section-4.2" ;
36+ public const string REQUEST_ENTITY_TOO_LARGE = BASE_URL + "rfc7231#section-6.5.11" ;
37+ public const string REQUEST_URI_TOO_LONG = BASE_URL + "rfc7231#section-6.5.12" ;
38+ public const string UNSUPPORTED_MEDIA_TYPE = BASE_URL + "rfc7231#section-6.5.13" ;
39+ public const string REQUESTED_RANGE_NOT_SATISFIABLE = BASE_URL + "rfc7233#section-4.4" ;
40+ public const string EXPECTATION_FAILED = BASE_URL + "rfc7231#section-6.5.14" ;
41+ public const string I_AM_A_TEAPOT = BASE_URL + "rfc2324#section-2.3.2" ;
42+ public const string UNPROCESSABLE_ENTITY = BASE_URL + "rfc4918#section-11.2" ;
43+ public const string TOO_EARLY = "https://httpwg.org/specs/rfc8470.html#status" ;
44+ public const string UPGRADE_REQUIRED = BASE_URL + "rfc7231#section-6.5.15" ;
45+ public const string PRECONDITION_REQUIRED = BASE_URL + "rfc6585#section-3" ;
46+ public const string TOO_MANY_REQUESTS = BASE_URL + "rfc6585#section-4" ;
47+ public const string REQUEST_HEADER_FIELDS_TOO_LARGE = BASE_URL + "rfc6585#section-5" ;
48+ public const string UNAVAILABLE_FOR_LEGAL_REASONS = "https://httpwg.org/specs/rfc7725.html#n-451-unavailable-for-legal-reasons" ;
49+ public const string INTERNAL_SERVER_ERROR = BASE_URL + "rfc7231#section-6.6.1" ;
50+ public const string NOT_IMPLEMENTED = BASE_URL + "rfc7231#section-6.6.2" ;
51+ public const string BAD_GATEWAY = BASE_URL + "rfc7231#section-6.6.3" ;
52+ public const string SERVICE_UNAVAILABLE = BASE_URL + "rfc7231#section-6.6.4" ;
53+ public const string GATEWAY_TIMEOUT = BASE_URL + "rfc7231#section-6.6.5" ;
54+ public const string HTTP_VERSION_NOT_SUPPORTED = BASE_URL + "rfc7231#section-6.6.6" ;
55+ public const string VARIANT_ALSO_NEGOTIATES = BASE_URL + "rfc2295#section-8.1" ;
56+ public const string INSUFFICIENT_STORAGE = BASE_URL + "rfc4918#section-11.5" ;
57+ public const string LOOP_DETECTED = BASE_URL + "rfc5842#section-7.2" ;
58+ public const string NOT_EXTENDED = BASE_URL + "rfc2774#section-7" ;
59+ public const string NETWORK_AUTHENTICATION_REQUIRED = BASE_URL + "rfc6585#section-6" ;
1560
16- public const string BAD_REQUEST = BASE_URL + "html/rfc7231#section-6.5.1" ;
17- public const string UNAUTHORIZED = BASE_URL + "html/rfc7235#section-3.1" ;
18- public const string PAYMENT_REQUIRED = BASE_URL + "html/rfc7231#section-6.5.2" ;
19- public const string FORBIDDEN = BASE_URL + "html/rfc7231#section-6.5.3" ;
20- public const string NOT_FOUND = BASE_URL + "html/rfc7231#section-6.5.4" ;
21- public const string METHOD_NOT_ALLOWED = BASE_URL + "html/rfc7231#section-6.5.5" ;
22- public const string NOT_ACCEPTABLE = BASE_URL + "html/rfc7231#section-6.5.6" ;
23- public const string PROXY_AUTHENTICATION_REQUIRED = BASE_URL + "html/rfc7235#section-3.2" ;
24- public const string REQUEST_TIMEOUT = BASE_URL + "html/rfc7231#section-6.5.7" ;
25- public const string CONFLICT = BASE_URL + "html/rfc7231#section-6.5.8" ;
26- public const string GONE = BASE_URL + "html/rfc7231#section-6.5.9" ;
27- public const string LENGTH_REQUIRED = BASE_URL + "html/rfc7231#section-6.5.10" ;
28- public const string PRECONDITION_FAILED = BASE_URL + "html/rfc7232#section-4.2" ;
29- public const string REQUEST_ENTITY_TOO_LARGE = BASE_URL + "html/rfc7231#section-6.5.11" ;
30- public const string REQUEST_URI_TOO_LONG = BASE_URL + "html/rfc7231#section-6.5.12" ;
31- public const string UNSUPPORTED_MEDIA_TYPE = BASE_URL + "html/rfc7231#section-6.5.13" ;
32- public const string REQUESTED_RANGE_NOT_SATISFIABLE = BASE_URL + "html/rfc7233#section-4.4" ;
33- public const string EXPECTATION_FAILED = BASE_URL + "html/rfc7231#section-6.5.14" ;
34- public const string UNPROCESSABLE_ENTITY = BASE_URL + "html/rfc4918#section-11.2" ;
35- public const string UPGRADE_REQUIRED = BASE_URL + "html/rfc7231#section-6.5.15" ;
36- public const string INTERNAL_SERVER_ERROR = BASE_URL + "html/rfc7231#section-6.6.1" ;
37- public const string NOT_IMPLEMENTED = BASE_URL + "html/rfc7231#section-6.6.2" ;
38- public const string BAD_GATEWAY = BASE_URL + "html/rfc7231#section-6.6.3" ;
39- public const string SERVICE_UNAVAILABLE = BASE_URL + "html/rfc7231#section-6.6.4" ;
40- public const string GATEWAY_TIMEOUT = BASE_URL + "html/rfc7231#section-6.6.5" ;
41- public const string HTTP_VERSION_NOT_SUPPORTED = BASE_URL + "html/rfc7231#section-6.6.6" ;
4261
4362 /// <summary>
4463 /// Get documentation link by status code
4564 /// </summary>
46- /// <param name="statuCode">Http statu code</param>
47- /// <exception cref="ArgumentException">The <paramref name="statuCode">info</paramref> parameter does not exist.</exception>
48- /// <returns>Documentation link</returns>
49- public static string GetStatusCodeLink ( this int statuCode )
65+ /// <param name="statuCode">Http status code</param>
66+ /// <returns>Documentation link. If the status code does not exists return NULL</returns>
67+ public static string GetStatusCodeLinkOrDefault ( this int statuCode )
5068 => statuCode switch
5169 {
5270 // 4XX
@@ -68,8 +86,14 @@ public static string GetStatusCodeLink(this int statuCode)
6886 415 => UNSUPPORTED_MEDIA_TYPE ,
6987 416 => REQUESTED_RANGE_NOT_SATISFIABLE ,
7088 417 => EXPECTATION_FAILED ,
89+ 418 => I_AM_A_TEAPOT ,
7190 422 => UNPROCESSABLE_ENTITY ,
91+ 425 => TOO_EARLY ,
7292 426 => UPGRADE_REQUIRED ,
93+ 428 => PRECONDITION_REQUIRED ,
94+ 429 => TOO_MANY_REQUESTS ,
95+ 431 => REQUEST_HEADER_FIELDS_TOO_LARGE ,
96+ 451 => UNAVAILABLE_FOR_LEGAL_REASONS ,
7397
7498 // 5XX
7599 500 => INTERNAL_SERVER_ERROR ,
@@ -78,14 +102,28 @@ public static string GetStatusCodeLink(this int statuCode)
78102 503 => SERVICE_UNAVAILABLE ,
79103 504 => GATEWAY_TIMEOUT ,
80104 505 => HTTP_VERSION_NOT_SUPPORTED ,
105+ 506 => VARIANT_ALSO_NEGOTIATES ,
106+ 507 => INSUFFICIENT_STORAGE ,
107+ 508 => LOOP_DETECTED ,
108+ 510 => NOT_EXTENDED ,
109+ 511 => NETWORK_AUTHENTICATION_REQUIRED ,
81110
82- _ => throw new ArgumentException ( $ "Unknown status code: ' { statuCode } '" ) ,
111+ _ => null ,
83112 } ;
84113
85114 /// <summary>
86115 /// Get documentation link by status code
87116 /// </summary>
88- /// <param name="statuCode">Http statu code</param>
117+ /// <param name="statuCode">Http status code</param>
118+ /// <exception cref="ArgumentException">The <paramref name="statuCode">info</paramref> parameter does not exist.</exception>
119+ /// <returns>Documentation link</returns>
120+ public static string GetStatusCodeLink ( this int statuCode )
121+ => statuCode . GetStatusCodeLinkOrDefault ( ) ?? throw new ArgumentException ( $ "Unknown status code: '{ statuCode } '") ;
122+
123+ /// <summary>
124+ /// Get documentation link by status code
125+ /// </summary>
126+ /// <param name="statuCode">Http status code</param>
89127 /// <exception cref="ArgumentException">The <paramref name="statuCode">info</paramref> parameter does not exist.</exception>
90128 /// <returns>Documentation link</returns>
91129 public static string GetStatusCodeLink ( this int ? statuCode )
0 commit comments