about summary refs log tree commit diff stats
path: root/adapter/protocol/curlerrors.nim
diff options
context:
space:
mode:
Diffstat (limited to 'adapter/protocol/curlerrors.nim')
-rw-r--r--adapter/protocol/curlerrors.nim17
1 files changed, 17 insertions, 0 deletions
diff --git a/adapter/protocol/curlerrors.nim b/adapter/protocol/curlerrors.nim
new file mode 100644
index 00000000..3bb6cf6d
--- /dev/null
+++ b/adapter/protocol/curlerrors.nim
@@ -0,0 +1,17 @@
+import bindings/curl
+import loader/connecterror
+
+func curlErrorToChaError*(res: CURLcode): ConnectErrorCode =
+  return case res
+  of CURLE_OK: CONNECTION_SUCCESS
+  of CURLE_URL_MALFORMAT: ERROR_INVALID_URL #TODO should never occur...
+  of CURLE_COULDNT_CONNECT: ERROR_CONNECTION_REFUSED
+  of CURLE_COULDNT_RESOLVE_PROXY: ERROR_FAILED_TO_RESOLVE_PROXY
+  of CURLE_COULDNT_RESOLVE_HOST: ERROR_FAILED_TO_RESOLVE_HOST
+  of CURLE_PROXY: ERROR_PROXY_REFUSED_TO_CONNECT
+  else: ERROR_INTERNAL
+
+proc getCurlConnectionError*(res: CURLcode): string =
+  let e = $int(curlErrorToChaError(res))
+  let msg = $curl_easy_strerror(res)
+  return "Cha-Control: ConnectionError " & e & " " & msg & "\n"