Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
Improve some error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Osvaldo Barrera committed Oct 13, 2019
1 parent 749398b commit bd0c52a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions django_mercadopago/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging

import requests
Expand Down Expand Up @@ -226,7 +227,7 @@ def poll_status(self):
response = response.json()

if response['results']:
logger.info('Polled for %s. Creating Payment', self.pk)
logger.info('Polled for %s. Found a Payment.', self.pk)
return Payment.objects.create_or_update_from_raw_data(
response['results'][-1]
)
Expand Down Expand Up @@ -323,6 +324,10 @@ def create_or_update_from_raw_data(self, raw_data):
mp_id=raw_data['id'],
defaults=payment_data,
)
if created:
logger.info('New payment created.')
else:
logger.info('Payment already registered locally, nothing created.')

if payment.status == 'approved' and \
payment.status_detail == 'accredited':
Expand Down Expand Up @@ -473,7 +478,14 @@ def process(self):
return

mercadopago_service = self.owner.service
raw_data = mercadopago_service.get_payment_info(self.resource_id)
try:
raw_data = mercadopago_service.get_payment_info(self.resource_id)
except json.JSONDecodeError:
# XXX: Actually, we need to write our own client that returns the
# real error (at least status code).
self.status = Notification.STATUS_ERROR
self.save()
return

if raw_data['status'] != 200:
logger.warning(
Expand Down

0 comments on commit bd0c52a

Please sign in to comment.