diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-09-28 17:54:13 +0200 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-09-28 17:54:13 +0200 |
| commit | 6a0e957e1f2c9f5bea0882efbf2e0494cd5074fa (patch) | |
| tree | 3d6206a2bc8676d2fd913c3958e5186fc3375c2b /src/loader/connecterror.nim | |
| parent | 9c257361388f5007871a36eea3abc815a8740d66 (diff) | |
| download | chawan-6a0e957e1f2c9f5bea0882efbf2e0494cd5074fa.tar.gz | |
loader: clean up connecterror
* allow string values for public errors
* remove unused errors
* update naming
Diffstat (limited to 'src/loader/connecterror.nim')
| -rw-r--r-- | src/loader/connecterror.nim | 90 |
1 files changed, 59 insertions, 31 deletions
diff --git a/src/loader/connecterror.nim b/src/loader/connecterror.nim index d8b06881..878bc8d0 100644 --- a/src/loader/connecterror.nim +++ b/src/loader/connecterror.nim @@ -1,36 +1,64 @@ -type ConnectErrorCode* = enum - ERROR_CGI_CACHED_BODY_NOT_FOUND = (-18, "cached request body not found") - ERROR_FAILED_TO_REDIRECT = (-17, "failed to redirect request body") - ERROR_URL_NOT_IN_CACHE = (-16, "URL was not found in the cache") - ERROR_FILE_NOT_IN_CACHE = (-15, "file was not found in the cache") - ERROR_FAILED_TO_EXECUTE_CGI_SCRIPT = (-14, "failed to execute CGI script") - ERROR_CGI_NO_DATA = (-13, "CGI script returned no data") - ERROR_CGI_MALFORMED_HEADER = (-12, "CGI script returned a malformed header") - ERROR_CGI_INVALID_CHA_CONTROL = (-11, "CGI got invalid Cha-Control header") - ERROR_TOO_MANY_REWRITES = (-10, "too many URI method map rewrites") - ERROR_INVALID_URI_METHOD_ENTRY = (-9, "invalid URI method entry") - ERROR_CGI_FILE_NOT_FOUND = (-8, "CGI file not found") - ERROR_INVALID_CGI_PATH = (-7, "invalid CGI path") - ERROR_FAIL_SETUP_CGI = (-6, "failed to set up CGI script") - ERROR_NO_CGI_DIR = (-5, "no local-CGI directory configured") - ERROR_SOURCE_NOT_FOUND = (-4, "clone source could not be found") - ERROR_LOADER_KILLED = (-3, "loader killed during transfer") - ERROR_DISALLOWED_URL = (-2, "url not allowed by filter") - ERROR_UNKNOWN_SCHEME = (-1, "unknown scheme") - CONNECTION_SUCCESS = (0, "connection successful") - ERROR_INTERNAL = (1, "internal error") - ERROR_INVALID_METHOD = (2, "invalid method") - ERROR_INVALID_URL = (3, "invalid URL") - ERROR_FILE_NOT_FOUND = (4, "file not found") - ERROR_CONNECTION_REFUSED = (5, "connection refused") - ERROR_PROXY_REFUSED_TO_CONNECT = (6, "proxy refused to connect") - ERROR_FAILED_TO_RESOLVE_HOST = (7, "failed to resolve host") - ERROR_FAILED_TO_RESOLVE_PROXY = (8, "failed to resolve proxy") +type ConnectionError* = enum + ceCGIOutputHandleNotFound = -17 + ceCGIFailedToOpenCacheOutput = -16 + ceCGICachedBodyNotFound = -15 + ceFailedToRedirect = -14 + ceURLNotInCache = -13 + ceFileNotInCache = -12 + ceFailedToExecuteCGIScript = -11 + ceCGIMalformedHeader = -10 + ceCGIInvalidChaControl = -9 + ceTooManyRewrites = -8 + ceInvalidURIMethodEntry = -7 + ceCGIFileNotFound = -6 + ceInvalidCGIPath = -5 + ceFailedToSetUpCGI = -4 + ceNoCGIDir = -3 + ceDisallowedURL = -2 + ceUnknownScheme = -1 + ceNone = 0 + ceInternalError = (1, "InternalError") + ceInvalidMethod = (2, "InvalidMethod") + ceInvalidURL = (3, "InvalidURL") + ceFileNotFound = (4, "FileNotFound") + ceConnectionRefused = (5, "ConnectionRefused") + ceProxyRefusedToConnect = (6, "ProxyRefusedToConnect") + ceFailedToResolveHost = (7, "FailedToResolveHost") + ceFailedToResolveProxy = (8, "FailedToResolveProxy") -converter toInt*(code: ConnectErrorCode): int = +const ErrorMessages* = [ + ceCGIOutputHandleNotFound: "request body output handle not found", + ceCGIFailedToOpenCacheOutput: "failed to open cache output", + ceCGICachedBodyNotFound: "cached request body not found", + ceFailedToRedirect: "failed to redirect request body", + ceURLNotInCache: "URL was not found in the cache", + ceFileNotInCache: "file was not found in the cache", + ceFailedToExecuteCGIScript: "failed to execute CGI script", + ceCGIMalformedHeader: "CGI script returned a malformed header", + ceCGIInvalidChaControl: "CGI got invalid Cha-Control header", + ceTooManyRewrites: "too many URI method map rewrites", + ceInvalidURIMethodEntry: "invalid URI method entry", + ceCGIFileNotFound: "CGI file not found", + ceInvalidCGIPath: "invalid CGI path", + ceFailedToSetUpCGI: "failed to set up CGI script", + ceNoCGIDir: "no local-CGI directory configured", + ceDisallowedURL: "url not allowed by filter", + ceUnknownScheme: "unknown scheme", + ceNone: "connection successful", + ceInternalError: "internal error", + ceInvalidMethod: "invalid method", + ceInvalidURL: "invalid URL", + ceFileNotFound: "file not found", + ceConnectionRefused: "connection refused", + ceProxyRefusedToConnect: "proxy refused to connect", + ceFailedToResolveHost: "failed to resolve host", + ceFailedToResolveProxy: "failed to resolve proxy", +] + +converter toInt*(code: ConnectionError): int = return int(code) func getLoaderErrorMessage*(code: int): string = - if code in int(ConnectErrorCode.low)..int(ConnectErrorCode.high): - return $ConnectErrorCode(code) + if code in int(ConnectionError.low)..int(ConnectionError.high): + return ErrorMessages[ConnectionError(code)] return "unexpected error code " & $code |