lundi 30 mars 2015

What's a more elegant way to check for null value in the following scenario?

I'm using Groovy. What's a more elegant way to do the following?



if (!token) {
token = this.getToken(key, callback)

if(!token) {
return params = null
}

}


So if a token is already present when a user comes into this flow, that token should be used. However, if the token isn't present, we should try to generate one. The service we're using to get the token doesn't throw an exception if none is created, it just returns null. If the token isn't successfully created (is still null) we want to set the params to null.


Is there a cleaner way to do what I'm doing? The null check within a null check seems ugly to me.


Aucun commentaire:

Enregistrer un commentaire