Skip to content

Commit

Permalink
[FIX] snailmail: change error code when timeout
Browse files Browse the repository at this point in the history
When the snailmail API-call timed out, the SnailmailLetter.state and SnailmailLetter.error_code were not changed, which resulted in an infinite loop of retries  via the "Snailmail: process letters queue" cron job.
This commit changes this behavior: On a timeout the SnailmailLetter.error_code is changed such that no retry happens. Following stable policy, no timeout error is added, but 'unknown error' will be used. Preventing retries on timeout is mandatory as timed-out request are indeed processed by IAP and customer credited.

closes #81659

Signed-off-by: Florian Daloze (fda) <fda@odoo.com>
  • Loading branch information
Dominik Zians committed Feb 8, 2022
1 parent fe932dd commit 1d84244
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions addons/snailmail/models/snailmail_letter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from odoo import fields, models, api, _, tools
from odoo.addons.iap import jsonrpc
from odoo.exceptions import UserError
from odoo.exceptions import UserError, AccessError
from odoo.tools.safe_eval import safe_eval

DEFAULT_ENDPOINT = 'https://iap-snailmail.odoo.com'
Expand Down Expand Up @@ -305,7 +305,14 @@ def _snailmail_print_valid_address(self):
endpoint = self.env['ir.config_parameter'].sudo().get_param('snailmail.endpoint', DEFAULT_ENDPOINT)
timeout = int(self.env['ir.config_parameter'].sudo().get_param('snailmail.timeout', DEFAULT_TIMEOUT))
params = self._snailmail_create('print')
response = jsonrpc(endpoint + PRINT_ENDPOINT, params=params, timeout=timeout)
try:
response = jsonrpc(endpoint + PRINT_ENDPOINT, params=params, timeout=timeout)
except AccessError as ae:
for doc in params['documents']:
letter = self.browse(doc['letter_id'])
letter.state = 'error'
letter.error_code = 'UNKNOWN_ERROR'
raise ae
for doc in response['request']['documents']:
if doc.get('sent') and response['request_code'] == 200:
note = _('The document was correctly sent by post.<br>The tracking id is %s' % doc['send_id'])
Expand Down

0 comments on commit 1d84244

Please sign in to comment.