about summary refs log blame commit diff stats
path: root/adapter/protocol/curlerrors.nim
blob: ce50cd822e2aa4d4547804eccf7b809078d28ab9 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
           















                                                                       
import 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"