github.com/swiftstack/proxyfs@v0.0.0-20201223034610-5434d919416e/swiftclient/http_status.go (about)

     1  // HTTP Status Code Decoder
     2  
     3  package swiftclient
     4  
     5  import (
     6  	"github.com/swiftstack/ProxyFS/blunder"
     7  )
     8  
     9  func httpStatusIsSuccess(httpStatus int) (isSuccess bool) {
    10  	return httpStatus >= 200 && httpStatus <= 299
    11  }
    12  
    13  func httpStatusIsError(httpStatus int) (isError bool, fsErr blunder.FsError) {
    14  
    15  	switch {
    16  
    17  	// 1xx Informational
    18  	//
    19  	// 100 Continue
    20  	// 101 Switching Protocols
    21  	// 102 Processing (WebDAV)
    22  	case httpStatus >= 100 && httpStatus <= 199:
    23  		return false, blunder.SuccessError
    24  
    25  	// 2xx Success
    26  	//
    27  	// 200 OK
    28  	// 201 Created
    29  	// 202 Accepted
    30  	// 203 Non-Authoritative Information
    31  	// 204 No Content
    32  	// 205 Reset Content
    33  	// 206 Partial Content
    34  	// 207 Multi-Status (WebDAV)
    35  	// 208 Already Reported (WebDAV)
    36  	// 226 IM Used
    37  	case httpStatus >= 200 && httpStatus <= 299:
    38  		return false, blunder.SuccessError
    39  
    40  	// 3xx Redirection
    41  	//
    42  	// 300 Multiple Choices
    43  	// 301 Moved Permanently
    44  	// 302 Found
    45  	// 303 See Other
    46  	// 304 Not Modified
    47  	// 305 Use Proxy
    48  	// 306 (Unused)
    49  	// 307 Temporary Redirect
    50  	// 308 Permanent Redirect (experiemental)
    51  	case httpStatus >= 300 && httpStatus <= 399:
    52  		// XXX TODO: Make error more unique?
    53  		return true, blunder.NotImplementedError
    54  
    55  	// 4xx Client Error
    56  	//
    57  
    58  	// 401 Unauthorized
    59  	case httpStatus == 401:
    60  		return true, blunder.NotPermError
    61  	// 403 Forbidden
    62  	case httpStatus == 403:
    63  		return true, blunder.NotPermError
    64  	// 404 Not Found
    65  	case httpStatus == 404:
    66  		return true, blunder.NotFoundError
    67  
    68  	// 400 Bad Request
    69  	// 402 Payment Required
    70  	// 405 Method Not Allowed
    71  	// 406 Not Acceptable
    72  	// 407 Proxy Authentication Required
    73  	// 408 Request Timeout
    74  
    75  	// 409 Conflict
    76  	case httpStatus == 409:
    77  		// Swift returns this error when one tries to delete a container that isn't empty
    78  		return true, blunder.NotEmptyError
    79  
    80  	// 410 Gone
    81  	// 411 Length Required
    82  	// 412 Precondition Failed
    83  	// 413 Request Entity Too Large
    84  	// 414 Request-URI Too Long
    85  	// 415 Unsupported Media Type
    86  	// 416 Requested Range Not Satisfiable
    87  	// 417 Expectation Failed
    88  	// 418 I'm a teapot (RFC 2324)
    89  	// 420 Enhance Your Calm (Twitter)
    90  	// 422 Unprocessable Entity (WebDAV)
    91  	// 423 Locked (WebDAV)
    92  	// 424 Failed Dependency (WebDAV)
    93  	// 425 Reserved for WebDAV
    94  	// 426 Upgrade Required
    95  	// 428 Precondition Required
    96  	// 429 Too Many Requests
    97  	// 431 Request Header Fields Too Large
    98  	// 444 No Response (Nginx)
    99  	// 449 Retry With (Microsoft)
   100  	// 450 Blocked by Windows Parental Controls (Microsoft)
   101  	// 451 Unavailable For Legal Reasons
   102  	// 499 Client Closed Request (Nginx)
   103  	case httpStatus >= 400 && httpStatus <= 499:
   104  		// XXX TODO: Make error more unique?
   105  		return true, blunder.NotImplementedError
   106  
   107  	// 5xx Server Error
   108  	//
   109  	// 500 Internal Server Error
   110  	// 501 Not Implemented
   111  	// 502 Bad Gateway
   112  	// 503 Service Unavailable
   113  	// 504 Gateway Timeout
   114  	// 505 HTTP Version Not Supported
   115  	// 506 Variant Also Negotiates (Experimental)
   116  	// 507 Insufficient Storage (WebDAV)
   117  	// 508 Loop Detected (WebDAV)
   118  	// 509 Bandwidth Limit Exceeded (Apache)
   119  	// 510 Not Extended
   120  	// 511 Network Authentication Required
   121  	// 598 Network read timeout error
   122  	// 599 Network connect timeout error
   123  	case httpStatus >= 500 && httpStatus <= 599:
   124  		// XXX TODO: Make error more unique?
   125  		return true, blunder.NotImplementedError
   126  
   127  	default:
   128  		// XXX TODO: Make error more unique?
   129  		return true, blunder.NotImplementedError
   130  	}
   131  }