`api_post_request` calls `handle_exception` so we will get the raised
exceptions. The reason we call `response.body` here is because
`api_post_request` only allows you to choose between `raw` and the default
for when it calls `handle_exception`. So, to keep the same functionality
that `exec_script` currently has we pass `true` as the 3rd parameter to
`api_post_request` so that we get the raw response back and then we return
the response's body. This mimics the call to `handle_exception(response,
'body')`.

A good fix would be to change the 3rd parameter to `api_post_request` to
allow you to select the type of response you want back from it, instead of
being just raw or default. But that would be on a separate pull request.

This code change maintains all the current functionality of `exec_script`
and adds the goodies from `api_post_request`, such as crumbs and cookies.

:)

--Thiago

------- __@       __@       __@       __@      __~@
----- _`\<,_    _`\<,_    _`\<,_    _`\<,_    _`\<,_
---- (*)/ (*)  (*)/ (*)  (*)/ (*)  (*)/ (*)  (*)/ (*)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



On Tue, Mar 11, 2014 at 5:24 PM, Kannan Manickam
<notifications@github.com>wrote:

> In lib/jenkins_api_client/client.rb:
>
> > @@ -544,13 +544,8 @@ def get_server_date
> >      # @return [String] The output of the executed groovy script
> >      #
> >      def exec_script(script_text)
> > -      url = URI.escape("#{@jenkins_path}/scriptText")
> > -      request = Net::HTTP::Post.new("#{url}")
> > -      request.form_data = { 'script' =>  script_text }
> > -      @logger.info "POST #{url}"
> > -
> > -      response = make_http_request(request)
> > -      handle_exception(response, 'body')
> > +      response = api_post_request('/scriptText', {'script' => script_text}, true)
> > +      response.body
>
> I think we should still go through the handle_exception so we raise any
> exception received.
>
> --
> Reply to this email directly or view it on GitHub<https://github.com/arangamani/jenkins_api_client/pull/128/files#r10501088>
> .
>