Skip to content

Commit

Permalink
Added error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed Jan 15, 2015
1 parent 3424afa commit 33688f4
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 14 deletions.
9 changes: 9 additions & 0 deletions src/openprocurement/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ def set_journal_handler(event):
'TAGS': 'python,api',
'USER_ID': str(event.request.authenticated_userid or ''),
'ROLE': str(event.request.authenticated_role),
'CURRENT_ROUTE_URL': event.request.current_route_url(),
'CURRENT_ROUTE_PATH': event.request.current_route_path(),
'AWARD_ID': '',
'BID_ID': '',
'COMPLAINT_ID': '',
'CONTRACT_ID': '',
'DOCUMENT_ID': '',
'QUESTION_ID': '',
'TENDER_ID': '',
}
if event.request.params:
params['PARAMS'] = str(dict(event.request.params))
Expand Down
11 changes: 11 additions & 0 deletions src/openprocurement/api/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from logging import getLogger
from base64 import b64encode
from jsonpatch import make_patch, apply_patch as _apply_patch
from openprocurement.api.models import Document, Revision, Award, get_now
Expand All @@ -7,6 +8,8 @@
from schematics.exceptions import ModelValidationError
from couchdb.http import ResourceConflict
from time import sleep
from cornice.util import json_error
from json import dumps


def generate_id():
Expand Down Expand Up @@ -184,3 +187,11 @@ def add_next_award(request):
else:
tender.awardPeriod.endDate = get_now()
tender.status = 'active.awarded'


def error_handler(errors):
LOGGER = getLogger('openprocurement.api')
LOGGER.info('Error on processing request "{}"'.format(dumps(errors, indent=4)), extra={'MESSAGE_ID': 'error_handler'})
for i in LOGGER.handlers:
LOGGER.removeHandler(i)
return json_error(errors)
6 changes: 5 additions & 1 deletion src/openprocurement/api/views/auction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
save_tender,
apply_patch,
add_next_award,
error_handler,
)
from openprocurement.api.validation import (
validate_tender_auction_data,
Expand All @@ -14,7 +15,10 @@
LOGGER = getLogger(__name__)


auction = Service(name='Tender Auction', path='/tenders/{tender_id}/auction', renderer='json')
auction = Service(name='Tender Auction',
path='/tenders/{tender_id}/auction',
renderer='json',
error_handler=error_handler)


@auction.get(renderer='json', permission='auction')
Expand Down
4 changes: 3 additions & 1 deletion src/openprocurement/api/views/award.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
apply_data_patch,
save_tender,
add_next_award,
error_handler,
)
from openprocurement.api.validation import (
validate_award_data,
Expand All @@ -19,7 +20,8 @@
@resource(name='Tender Awards',
collection_path='/tenders/{tender_id}/awards',
path='/tenders/{tender_id}/awards/{award_id}',
description="Tender awards")
description="Tender awards",
error_handler=error_handler)
class TenderAwardResource(object):

def __init__(self, request):
Expand Down
4 changes: 3 additions & 1 deletion src/openprocurement/api/views/award_complaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
apply_data_patch,
save_tender,
add_next_award,
error_handler,
)
from openprocurement.api.validation import (
validate_complaint_data,
Expand All @@ -19,7 +20,8 @@
@resource(name='Tender Award Complaints',
collection_path='/tenders/{tender_id}/awards/{award_id}/complaints',
path='/tenders/{tender_id}/awards/{award_id}/complaints/{complaint_id}',
description="Tender award complaints")
description="Tender award complaints",
error_handler=error_handler)
class TenderAwardComplaintResource(object):

def __init__(self, request):
Expand Down
4 changes: 3 additions & 1 deletion src/openprocurement/api/views/award_complaint_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
save_tender,
upload_file,
apply_patch,
error_handler,
)
from openprocurement.api.validation import (
validate_file_update,
Expand All @@ -20,7 +21,8 @@
@resource(name='Tender Award Complaint Documents',
collection_path='/tenders/{tender_id}/awards/{award_id}/complaints/{complaint_id}/documents',
path='/tenders/{tender_id}/awards/{award_id}/complaints/{complaint_id}/documents/{document_id}',
description="Tender award complaint documents")
description="Tender award complaint documents",
error_handler=error_handler)
class TenderAwardComplaintDocumentResource(object):

def __init__(self, request):
Expand Down
4 changes: 3 additions & 1 deletion src/openprocurement/api/views/award_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from openprocurement.api.utils import (
apply_patch,
save_tender,
error_handler,
)
from openprocurement.api.validation import (
validate_contract_data,
Expand All @@ -18,7 +19,8 @@
@resource(name='Tender Award Contracts',
collection_path='/tenders/{tender_id}/awards/{award_id}/contracts',
path='/tenders/{tender_id}/awards/{award_id}/contracts/{contract_id}',
description="Tender award contracts")
description="Tender award contracts",
error_handler=error_handler)
class TenderAwardContractResource(object):

def __init__(self, request):
Expand Down
4 changes: 3 additions & 1 deletion src/openprocurement/api/views/award_contract_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
save_tender,
upload_file,
apply_patch,
error_handler,
)
from openprocurement.api.validation import (
validate_file_update,
Expand All @@ -20,7 +21,8 @@
@resource(name='Tender Award Contract Documents',
collection_path='/tenders/{tender_id}/awards/{award_id}/contracts/{contract_id}/documents',
path='/tenders/{tender_id}/awards/{award_id}/contracts/{contract_id}/documents/{document_id}',
description="Tender award contract documents")
description="Tender award contract documents",
error_handler=error_handler)
class TenderAwardContractDocumentResource(object):

def __init__(self, request):
Expand Down
4 changes: 3 additions & 1 deletion src/openprocurement/api/views/award_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
save_tender,
upload_file,
apply_patch,
error_handler,
)
from openprocurement.api.validation import (
validate_file_update,
Expand All @@ -20,7 +21,8 @@
@resource(name='Tender Award Documents',
collection_path='/tenders/{tender_id}/awards/{award_id}/documents',
path='/tenders/{tender_id}/awards/{award_id}/documents/{document_id}',
description="Tender award documents")
description="Tender award documents",
error_handler=error_handler)
class TenderAwardDocumentResource(object):

def __init__(self, request):
Expand Down
4 changes: 3 additions & 1 deletion src/openprocurement/api/views/bid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
save_tender,
set_ownership,
apply_patch,
error_handler,
)
from openprocurement.api.validation import (
validate_bid_data,
Expand All @@ -19,7 +20,8 @@
@resource(name='Tender Bids',
collection_path='/tenders/{tender_id}/bids',
path='/tenders/{tender_id}/bids/{bid_id}',
description="Tender bids")
description="Tender bids",
error_handler=error_handler)
class TenderBidResource(object):

def __init__(self, request):
Expand Down
4 changes: 3 additions & 1 deletion src/openprocurement/api/views/bid_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
save_tender,
upload_file,
apply_patch,
error_handler,
)
from openprocurement.api.validation import (
validate_file_update,
Expand All @@ -20,7 +21,8 @@
@resource(name='Tender Bid Documents',
collection_path='/tenders/{tender_id}/bids/{bid_id}/documents',
path='/tenders/{tender_id}/bids/{bid_id}/documents/{document_id}',
description="Tender bidder documents")
description="Tender bidder documents",
error_handler=error_handler)
class TenderBidDocumentResource(object):

def __init__(self, request):
Expand Down
4 changes: 3 additions & 1 deletion src/openprocurement/api/views/complaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from openprocurement.api.utils import (
apply_patch,
save_tender,
error_handler,
)
from openprocurement.api.validation import (
validate_complaint_data,
Expand All @@ -18,7 +19,8 @@
@resource(name='Tender Complaints',
collection_path='/tenders/{tender_id}/complaints',
path='/tenders/{tender_id}/complaints/{complaint_id}',
description="Tender complaints")
description="Tender complaints",
error_handler=error_handler)
class TenderComplaintResource(object):

def __init__(self, request):
Expand Down
4 changes: 3 additions & 1 deletion src/openprocurement/api/views/complaint_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
save_tender,
upload_file,
apply_patch,
error_handler,
)
from openprocurement.api.validation import (
validate_file_update,
Expand All @@ -20,7 +21,8 @@
@resource(name='Tender Complaint Documents',
collection_path='/tenders/{tender_id}/complaints/{complaint_id}/documents',
path='/tenders/{tender_id}/complaints/{complaint_id}/documents/{document_id}',
description="Tender complaint documents")
description="Tender complaint documents",
error_handler=error_handler)
class TenderComplaintDocumentResource(object):

def __init__(self, request):
Expand Down
4 changes: 3 additions & 1 deletion src/openprocurement/api/views/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from openprocurement.api.utils import (
apply_patch,
save_tender,
error_handler,
)
from openprocurement.api.validation import (
validate_question_data,
Expand All @@ -18,7 +19,8 @@
@resource(name='Tender Questions',
collection_path='/tenders/{tender_id}/questions',
path='/tenders/{tender_id}/questions/{question_id}',
description="Tender questions")
description="Tender questions",
error_handler=error_handler)
class TenderQuestionResource(object):

def __init__(self, request):
Expand Down
4 changes: 3 additions & 1 deletion src/openprocurement/api/views/tender.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
tender_serialize,
apply_patch,
add_next_award,
error_handler,
)
from openprocurement.api.validation import (
validate_patch_tender_data,
Expand All @@ -25,7 +26,8 @@
@resource(name='Tender',
collection_path='/tenders',
path='/tenders/{tender_id}',
description="Open Contracting compatible data exchange format. See http://ocds.open-contracting.org/standard/r/master/#tender for more info")
description="Open Contracting compatible data exchange format. See http://ocds.open-contracting.org/standard/r/master/#tender for more info",
error_handler=error_handler)
class TenderResource(object):

def __init__(self, request):
Expand Down
4 changes: 3 additions & 1 deletion src/openprocurement/api/views/tender_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
save_tender,
upload_file,
apply_patch,
error_handler,
)
from openprocurement.api.validation import (
validate_file_update,
Expand All @@ -20,7 +21,8 @@
@resource(name='Tender Documents',
collection_path='/tenders/{tender_id}/documents',
path='/tenders/{tender_id}/documents/{document_id}',
description="Tender related binary files (PDFs, etc.)")
description="Tender related binary files (PDFs, etc.)",
error_handler=error_handler)
class TenderDocumentResource(object):

def __init__(self, request):
Expand Down

0 comments on commit 33688f4

Please sign in to comment.