Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,466,185
Community Members
 
Community Events
176
Community Groups

Groovy script error

import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.TEXT

// initialize a new builder and give a default URL
def http = new HTTPBuilder("https://www.google.com/")

return http.request(GET,TEXT) { req ->

response.success = { resp, htmlText ->
assert resp.status == 200
log.debug("My response handler got response: ${resp.statusLine}")
if(htmlText){
return htmlText.getText()
}
else{
return null
}
}

// called only for a 404 (not found) status code:
response."404" = { resp ->
log.error ("Not found")
return null
}
}

IM getting variable[response]is not declared

1 answer

1 accepted

0 votes
Answer accepted

There is nothing wrong with the script. Did you try to run it?

Sometimes, the script editor will report static type checking errors because it's unable to confirm the script is okay or not. Because groovy doesn't require objects and variables to be strongly typed, these sorts of errors can sometimes appear. They are not always something that needs to be resolved.

In this case, the httpbuilder will have defined that variable. But your code editor can't guess that ahead of time.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events