Reputation: 2720
I'm having trouble catching an CertificateExpiredException in Grails. When I add the exception in the code, I get a "Catch statement parameter type is not a subclass of Throwable." message. If I put a generic "Exception" as a catch parameter, it works. How I can trap this SSL error and provide a meaningful response for the user?
Here's an example 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
}
}
}
Upvotes: 3
Views: 2185
Reputation: 75671
You need to add an import:
import java.security.cert.CertificateExpiredException
class MyService {
...
}
Upvotes: 4