arangamani/jenkins_api_client — pull request #97 by dougforpres (2013-08-01 22:41:06+00:00)
Title: Crumbs + Exceptions fixes

Hi,

This is pull part one of two. I was adding support for a new "client.user" api subclass when the following issues were encountered.

#1 Our jenkins has XSS protection disabled, so no crumbs. I was trying to execute job creation and was getting weird 'Crumb' errors thrown at me. Turns out the api was getting forbidden because I do not have permission to create jobs, and the Text of the forbidden error was pointing me at crumbs.
So I added a subclass of Forbidden that is only raised IFF crumbs are on and a forbidden is encountered.
The text of the error was still wrong, at which time I found...
#2 The code in the base exceptions that checks for 'message' param was only using it to determine whether or not to set default text. If a message was passed in, the default was not being set, but the passed value wasn't being used either.
#3 A big part of the text on the forbidden error relating to crumbs dealt with restarting the app. I changed the code to do the following on a 'forbidden' error:
- check to see if the 'crumbs enabled' value has changed on jenkins.
- if it has, set flag accordingly, and set @crumbs accordingly - then retry
- if it hasn't, refresh crumb (as per previous behavior)
- if retry limit reached, don't re-raise the forbidden, create a new 'ForbiddenWithCrumb' (derived from Forbidden, so existing code won't break). This new exception adds "and I tried with crumbs too" type text to forbidden error.

Hope this all makes sense.
On my test rig it all sends the correct errors, and the tests still pass.
Please let me know if there are any questions. I tried to add comments to make things easier to understand.

Doug