Certificate Satisfaction Excluded Exceptions in Grails
I am having trouble acquiring the CertificateExpiredException in Grails. When I add an exception to the code, I get "The parameter type of the 'Catch statement' is not a Throwable subclass". message. If I use the generic Exception parameter as the catch parameter it works. How can I catch this SSL error and give a meaningful response to the user?
Here's an example of a service:
class MyService {
static transactional = false
String someUrl = 'https://example.com'
def getThings() {
def conn
try {
conn = someUrl.toURL().openConnection()
} catch (CertificateExpiredException e) { // doesn't like this
log.debug e // doesn't work?
return "SSL error, no results returned."
}
if(conn.responseCode == 200){
// do stuff
}
}
}
+3
arcdegree
source
to share
1 answer
You need to add imports:
import java.security.cert.CertificateExpiredException
class MyService {
...
}
+4
Burt beckwith
source
to share