Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get cURL error code #78

Open
dwill20 opened this issue Jan 14, 2021 · 1 comment
Open

Get cURL error code #78

dwill20 opened this issue Jan 14, 2021 · 1 comment

Comments

@dwill20
Copy link

dwill20 commented Jan 14, 2021

I haven't found a way to get cURL error code so far. When using EasyInit, it's returning error message string like curl: Couldn't resolve host name.

func main() {
        easy := curl.EasyInit()
	defer easy.Cleanup()

	easy.Setopt(curl.OPT_URL, "http://zzzzzzzz---.com")

	if err := easy.Perform(); err != nil {
		fmt.Println(err, err.Error())
	}
}

But, how to get the cURL error code like the libcurl equivalent returns.

int main(int argc, char *argv[]) {
    CURL *easyhandle = curl_easy_init();
    curl_easy_setopt(easyhandle, CURLOPT_URL, "http://zzzzzzzz---.com");
    int errorCode = curl_easy_perform(easyhandle);
    printf("Error Code: %d %d\n", errorCode, errorCode == CURLE_COULDNT_RESOLVE_HOST);
    return 0;
}
@hwshadow
Copy link

hwshadow commented Apr 26, 2023

This is a bit hacky but you could do the following to extract the int errorCode from the curl error provided by this library.

errornum, convErr := strconv.Atoi(fmt.Sprintf("%d", err.(curl.CurlError) ))

Sorry this is so late, I just ran into this as well ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants