program exit status code constants success 0 error 1 errortimeout 2 see checkstatus errorhttp3xx 3 errorhttp4xx 4 errorhttp5xx 5 errortoomanyredirects 6 pluginerror 7 1282 sigint http www tldp orgldpabshtmlexitcodes html errorctrlc 130 def httpstatustoexitstatushttpstatus int followfalse exitstatus if 300 httpstatus 399 and not follow redirect return exitstatus errorhttp3xx elif 400 httpstatus 499 client error return exitstatus errorhttp4xx elif 500 httpstatus 599 server error return exitstatus errorhttp5xx else return exitstatus success program exit status code constants see check status 128 2 sigint http www tldp org ldp abs html exitcodes html translate http status code to exit status code relevant only when invoked with check status or download redirect client error server error
from enum import IntEnum, unique


@unique
class ExitStatus(IntEnum):
    
    SUCCESS = 0
    ERROR = 1
    ERROR_TIMEOUT = 2

    
    ERROR_HTTP_3XX = 3
    ERROR_HTTP_4XX = 4
    ERROR_HTTP_5XX = 5

    ERROR_TOO_MANY_REDIRECTS = 6
    PLUGIN_ERROR = 7
    
    
    ERROR_CTRL_C = 130


def http_status_to_exit_status(http_status: int, follow=False) -> ExitStatus:
    
    if 300 <= http_status <= 399 and not follow:
        
        return ExitStatus.ERROR_HTTP_3XX
    elif 400 <= http_status <= 499:
        
        return ExitStatus.ERROR_HTTP_4XX
    elif 500 <= http_status <= 599:
        
        return ExitStatus.ERROR_HTTP_5XX
    else:
        return ExitStatus.SUCCESS