# Path: pypd/errors.py
# class BadRequest(Error):
#     def __init__(self, code=400, message='', *args, **kwargs):
#         self.code = code
#         self.message = message
#         self.errors = []
# 
#         Error.__init__(self, *args, **kwargs)
# 
#         try:
#             obj = json.loads(message)['error']
#             self.code = obj.get('code', code)
#             self.message = obj.get('message', message)
#             self.errors = obj.get('errors', [])
#         except:
#             pass
# 
#     def __str__(self):
#         error = '{0} ({1}): {2}'.format(self.__class__.__name__, self.code,
#                                         self.message)
#         if self.errors:
#             addon = self.errors[0] if len(self.errors) == 1 else self.errors
#             error = '{0} - {1}'.format(error, addon)
# 
#         return error


from os.path import dirname, join
from time import sleep
from pprint import pprint
from pypd.errors import BadRequest
import logging
import pypd
    'incident_key': 'incident_demo_key',
    'body': {
        'type': 'incident_body',
        'details': 'testing creating an incident',
    },
    'escalation_policy': {
        'id': escalation_policy['id'],
        'type': 'escalation_policy_reference',
    }
}

# if the incident is already open it will error with BadRequest
try:
    incident = pypd.Incident.create(
        data=data,
        add_headers={'from': from_email, },
    )
except BadRequest:
    incident = pypd.Incident.find(incident_key='incident_demo_key')[-1]

# mergable incident
data_mergable = data.copy()
mergable_key = 'incident_demo_key_mergable'
data_mergable['incident_key'] = mergable_key

try:
    to_merge = pypd.Incident.create(
        data=data_mergable,
        add_headers={'from': from_email, }
    )

# Path: pypd/errors.py
# class BadRequest(Error):
#     def __init__(self, code=400, message='', *args, **kwargs):
#         self.code = code
#         self.message = message
#         self.errors = []
# 
#         Error.__init__(self, *args, **kwargs)
# 
#         try:
#             obj = json.loads(message)['error']
#             self.code = obj.get('code', code)
#             self.message = obj.get('message', message)
#             self.errors = obj.get('errors', [])
#         except:
#             pass
# 
#     def __str__(self):
#         error = '{0} ({1}): {2}'.format(self.__class__.__name__, self.code,
#                                         self.message)
#         if self.errors:
#             addon = self.errors[0] if len(self.errors) == 1 else self.errors
#             error = '{0} - {1}'.format(error, addon)
# 
#         return error


# Path: examples/incident_demo.py
from os.path import dirname, join
from time import sleep
from pprint import pprint
from pypd.errors import BadRequest
import logging
import pypd

    'incident_key': 'incident_demo_key',
    'body': {
        'type': 'incident_body',
        'details': 'testing creating an incident',
    },
    'escalation_policy': {
        'id': escalation_policy['id'],
        'type': 'escalation_policy_reference',
    }
}

# if the incident is already open it will error with BadRequest
try:
    incident = pypd.Incident.create(
        data=data,
        add_headers={'from': from_email, },
    )
except BadRequest:
    incident = pypd.Incident.find(incident_key='incident_demo_key')[-1]

# mergable incident
data_mergable = data.copy()
mergable_key = 'incident_demo_key_mergable'
data_mergable['incident_key'] = mergable_key

try:
    to_merge = pypd.Incident.create(
        data=data_mergable,
        add_headers={'from': from_email, }
    )

except BadRequest: