1+ angular
2+ . module ( 'ngHttpStatus' , [ ] )
3+ . constant ( 'HttpCodes' , {
4+ CONTINUE : 100 , // RFC7231 @6.2.1 : https://tools.ietf.org/html/rfc7231#section-6.2.1
5+ SWITCHING_PROTOCOLS : 101 , // RFC7231 @6.2.2 : https://tools.ietf.org/html/rfc7231#section-6.2.2
6+ PROCESSING : 102 , // RFC2518 : https://tools.ietf.org/html/rfc2518
7+
8+ OK : 200 , // RFC7231 @6.3.1 : https://tools.ietf.org/html/rfc7231#section-6.3.1
9+ CREATED : 201 , // RFC7231 @6.3.2 : https://tools.ietf.org/html/rfc7231#section-6.3.2
10+ ACCEPTED : 202 , // RFC7231 @6.3.3 : https://tools.ietf.org/html/rfc7231#section-6.3.3
11+ NON_AUTHORITATIVE_INFORMATION : 203 , // RFC7231 @6.3.4 : https://tools.ietf.org/html/rfc7231#section-6.3.4
12+ NO_CONTENT : 204 , // RFC7231 @6.3.5 : https://tools.ietf.org/html/rfc7231#section-6.3.5
13+ RESET_CONTENT : 205 , // RFC7231 @6.3.6 : https://tools.ietf.org/html/rfc7231#section-6.3.6
14+ PARTIAL_CONTENT : 206 , // RFC7233 @4.1 : https://tools.ietf.org/html/rfc7233#section-4.1
15+ MULTI_STATUS : 207 , // RFC4918 : https://tools.ietf.org/html/rfc4918
16+ ALREADY_REPORTED : 208 , // RFC5842 : https://tools.ietf.org/html/rfc5842
17+ IM_USED : 226 , // RFC3239 : https://tools.ietf.org/html/rfc3239
18+
19+ MULTIPLE_CHOICES : 300 , // RFC7231 @6.4.1 : https://tools.ietf.org/html/rfc7231#section-6.4.1
20+ MOVED_PERMANENTLY : 301 , // RFC7231 @6.4.2 : https://tools.ietf.org/html/rfc7231#section-6.4.2
21+ FOUND : 302 , // RFC7231 @6.4.3 : https://tools.ietf.org/html/rfc7231#section-6.4.3
22+ SEE_OTHER : 303 , // RFC7231 @6.4.4 : https://tools.ietf.org/html/rfc7231#section-6.4.4
23+ NOT_MODIFIED : 304 , // RFC7232 @4.1 : https://tools.ietf.org/html/rfc7232#section-4.1
24+ USE_PROXY : 305 , // RFC7231 @6.4.5 : https://tools.ietf.org/html/rfc7231#section-6.4.5
25+ UNUSED : 306 , // RFC7231 @6.4.6 : https://tools.ietf.org/html/rfc7231#section-6.4.6
26+ TEMPORARY_REDIRECT : 307 , // RFC7231 @6.4.7 : https://tools.ietf.org/html/rfc7231#section-6.4.7
27+ PERMANENT_REDIRECT : 308 , // RFC7538 : https://tools.ietf.org/html/rfc7538
28+ TOO_MANY_REDIRECTS : 310 ,
29+
30+ BAD_REQUEST : 400 , // RFC7231 @6.5.1 : https://tools.ietf.org/html/rfc7231#section-6.5.1
31+ UNAUTHORIZED : 401 , // RFC7235 @3.1 : https://tools.ietf.org/html/rfc7235#section-3.1
32+ PAYMENT_REQUIRED : 402 , // RFC7231 @6.5.2 : https://tools.ietf.org/html/rfc7231#section-6.5.2
33+ FORBIDDEN : 403 , // RFC7231 @6.5.3 : https://tools.ietf.org/html/rfc7231#section-6.5.3
34+ NOT_FOUND : 404 , // RFC7231 @6.5.4 : https://tools.ietf.org/html/rfc7231#section-6.5.4
35+ METHOD_NOT_ALLOWED : 405 , // RFC7231 @6.5.5 : https://tools.ietf.org/html/rfc7231#section-6.5.5
36+ NOT_ACCEPTABLE : 406 , // RFC7231 @6.5.6 : https://tools.ietf.org/html/rfc7231#section-6.5.6
37+ PROXY_AUTHENTICATION_REQUIRED : 407 , // RFC7235 @3.2 : https://tools.ietf.org/html/rfc7235#section-3.2
38+ REQUEST_TIMEOUT : 408 , // RFC7231 @6.5.7 : https://tools.ietf.org/html/rfc7231#section-6.5.7
39+ CONFLICT : 409 , // RFC7231 @6.5.8 : https://tools.ietf.org/html/rfc7231#section-6.5.8
40+ GONE : 410 , // RFC7231 @6.5.9 : https://tools.ietf.org/html/rfc7231#section-6.5.9
41+ LENGTH_REQUIRED : 411 , // RFC7231 @6.5.10 : https://tools.ietf.org/html/rfc7231#section-6.5.10
42+ PRECONDITION_FAILED : 412 , // RFC7232 @4.2 : https://tools.ietf.org/html/rfc7232#section-4.2
43+ PAYLOAD_TOO_LARGE : 413 , // RFC7231 @6.5.11 : https://tools.ietf.org/html/rfc7231#section-6.5.11
44+ URI_TOO_LONG : 414 , // RFC7231 @6.5.12 : https://tools.ietf.org/html/rfc7231#section-6.5.12
45+ UNSUPPORTED_MEDIA_TYPE : 415 , // RFC7231 @6.5.13 : https://tools.ietf.org/html/rfc7231#section-6.5.13
46+ RANGE_NOT_SATISFIABLE : 416 , // RFC7233 @4.4 : https://tools.ietf.org/html/rfc7233#section-4.4
47+ EXPECTATION_FAILED : 417 , // RFC7231 @6.5.14 : https://tools.ietf.org/html/rfc7231#section-6.5.14
48+ IM_A_TEAPOT : 418 , // RFC2324 : https://tools.ietf.org/html/rfc2324
49+ MISDIRECT_REQUEST : 421 , // RFC7540 @9.1.2 : https://tools.ietf.org/html/rfc7540#section-9.1.2
50+ UNPROCESSABLE_ENTITY : 422 , // RFC4918 : https://tools.ietf.org/html/rfc4918
51+ LOCKED : 423 , // RFC4918 : https://tools.ietf.org/html/rfc4918
52+ FAILED_DEPENDENCY : 424 , // RFC4918 : https://tools.ietf.org/html/rfc4918
53+ UNORDERED_COLLEcTION : 425 , // RFC3648 : https://tools.ietf.org/html/rfc3648
54+ UPGRADE_REQUIRED : 426 , // RFC7231 @6.5.15 : https://tools.ietf.org/html/rfc7231#section-6.5.15
55+ PRECONDITION_REQUIRED : 428 , // RFC6585 : https://tools.ietf.org/html/rfc6585
56+ TOO_MANY_REQUEST : 429 , // RFC6585 : https://tools.ietf.org/html/rfc6585
57+ REQUEST_HEADER_FIELDS_TOO_LARGE : 431 , // RFC6585 : https://tools.ietf.org/html/rfc6585
58+
59+ INTERNAL_SERVER_ERROR : 500 , // RFC7231 @6.6.1 : https://tools.ietf.org/html/rfc7231#section-6.6.1
60+ NOT_IMPLEMENTED : 501 , // RFC7231 @6.6.2 : https://tools.ietf.org/html/rfc7231#section-6.6.2
61+ BAD_GATEWAY : 502 , // RFC7231 @6.6.3 : https://tools.ietf.org/html/rfc7231#section-6.6.3
62+ SERVICE_UNAVAILABLE : 503 , // RFC7231 @6.6.4 : https://tools.ietf.org/html/rfc7231#section-6.6.4
63+ GATEWAY_TIMEOUT : 504 , // RFC7231 @6.6.5 : https://tools.ietf.org/html/rfc7231#section-6.6.5
64+ HTTP_VERSION_NOT_SUPPORTED : 505 , // RFC7231 @6.6.6 : https://tools.ietf.org/html/rfc7231#section-6.6.6
65+ VARIANT_ALSO_NEGOTIATES : 506 , // RFC2295 : https://tools.ietf.org/html/rfc2295
66+ INSUFFICIENT_STORAGE : 507 , // RFC4918 : https://tools.ietf.org/html/rfc4918
67+ LOOP_DETECTED : 508 , // RFC5842 : https://tools.ietf.org/html/rfc5842
68+ NOT_EXTENDED : 510 , // RFC2774 : https://tools.ietf.org/html/rfc2774
69+ NETWORK_AUTHENTICATION_REQUIRED : 511 // RFC6585 : https://tools.ietf.org/html/rfc6585
70+ } )
71+ . factory ( 'HttpStatus' , [ 'HttpCodes' , function ( HttpCodes ) {
72+ return {
73+ toString : function ( status ) {
74+ if ( angular . isNumber ( status ) === false ) {
75+ throw new TypeError ( status + ' is not a number and obviously not a valid HTTP status code.' )
76+ }
77+
78+ var statusName = '' ;
79+ var keys = Object . keys ( HttpCodes ) ;
80+
81+ for ( var i = 0 ; i < keys . length ; i ++ ) {
82+ if ( HttpCodes [ keys [ i ] ] === status ) {
83+ statusName = keys [ i ] . replace ( '_' , ' ' ) . toLowerCase ( ) ;
84+ break ;
85+ }
86+ }
87+
88+ return ( statusName . length > 0 )
89+ ? statusName [ 0 ] . toUpperCase ( ) + statusName . substr ( 1 )
90+ : undefined ;
91+ }
92+ } ;
93+ } ] ) ;
0 commit comments