Skip to content

Commit

Permalink
Add some http-error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
chaosblog committed Feb 8, 2013
1 parent 48ac7a9 commit 0f53847
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions autojenkins/jobs.py
Expand Up @@ -3,6 +3,13 @@
import requests
from jinja2 import Template

class AutojenkinsError(Exception):
pass
class JobInexistent(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return repr(self.msg)

API = 'api/python'
NEWJOB = '{0}/createItem'
Expand All @@ -24,13 +31,21 @@
class HttpStatusError(Exception):
pass

class HttpUnauthorized(Exception):
pass


class HttpForbidden(Exception):
pass

class HttpNotFoundError(HttpStatusError):
pass


HTTP_ERROR_MAP = {
404: HttpNotFoundError,
401: HttpUnauthorized, #credentials wrong
403: HttpForbidden, #insufficient rights
404: HttpNotFoundError
}


Expand Down Expand Up @@ -277,7 +292,7 @@ def delete(self, jobname):
if self.job_exists(jobname):
return self._build_post(DELETE, jobname)
else:
raise Exception("Job doesn't exist")
raise JobInexistent("Job '%s' doesn't exist" % jobname)

def enable(self, jobname):
"""
Expand Down

0 comments on commit 0f53847

Please sign in to comment.