I am trying to catch SslError in some HttpClient code.
import net, httpclient
try:
var client = newHttpClient(timeout=500)
except SslError:
echo("caught SslError")
#Gives this error
#~/ntplayground2.nim(5, 8) Error: undeclared identifier: 'SslError'
To my understanding SslError is in the net module.
https://nim-lang.org/docs/net.html#SslError
I do not understand why it is undeclared? Or how to resolve the problem.
Thanks.
What compile flags are you using?
If you look at the source of the net module, all of the ssl types are defined inside a compile time if statement. The when defineSsl block: https://github.com/nim-lang/Nim/blob/master/lib/pure/net.nim#L82
If you do not compile your program with the -d:ssl flag, those types don't ever get compiled, so you can't catch them.
You must remember to use the -d:ssl flag when compiling or If you want your code to work both with and without ssl support, you also must use when defineSsl:.
Ah okay, silly mistake on my part. That fixes it. I have another app which uses the code with the SslError and it compiled without problem but I was using the -d:ssl flag to compile it. I did not notice I was doing it differently here.
Thanks for your patience with my mistake.