Reputation: 166
I'm trying to receive status code with url calls.(Using grails)
def http = new HttpResponseDecorator(url)
// Authentication header
http.auth.basic(username, password)
// Http request method. Pulls out json file
http.request(Method.GET) {
response.success = {
render "Success!"
}
response.failure = { resp ->;
render resp
}
}
Trying this code snippet to receive make url calls, but I can't figure out how to pull out status code from this.
What I want to do is sending error messages depending on what status code I'm getting.(for example, 400 prints forbidden message of my choice)
Any suggestions for a class to receive status code of the GET calls?
Upvotes: 0
Views: 532
Reputation: 19682
The resp
argument to your response.failure
closure has a status
you can check.
response.failiure = { resp ->
if (resp.status == 400) {
// render forbidden message
}
}
See the Response Handlers section of the httpbuilder docs for more information and examples.
Upvotes: 2