Skip to content

Commit b3c46e8

Browse files
author
Dominik Zians
committed
[FIX] snailmail: change error code when timeout
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 odoo#84202 X-original-commit: 1d84244 Signed-off-by: Florian Daloze (fda) <fda@odoo.com>
1 parent 682030f commit b3c46e8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

addons/snailmail/models/snailmail_letter.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from odoo import fields, models, api, _
77
from odoo.addons.iap.tools import iap_tools
8+
from odoo.exceptions import AccessError
89
from odoo.tools.safe_eval import safe_eval
910

1011
DEFAULT_ENDPOINT = 'https://iap-snailmail.odoo.com'
@@ -336,7 +337,14 @@ def _snailmail_print_valid_address(self):
336337
endpoint = self.env['ir.config_parameter'].sudo().get_param('snailmail.endpoint', DEFAULT_ENDPOINT)
337338
timeout = int(self.env['ir.config_parameter'].sudo().get_param('snailmail.timeout', DEFAULT_TIMEOUT))
338339
params = self._snailmail_create('print')
339-
response = iap_tools.iap_jsonrpc(endpoint + PRINT_ENDPOINT, params=params, timeout=timeout)
340+
try:
341+
response = iap_tools.iap_jsonrpc(endpoint + PRINT_ENDPOINT, params=params, timeout=timeout)
342+
except AccessError as ae:
343+
for doc in params['documents']:
344+
letter = self.browse(doc['letter_id'])
345+
letter.state = 'error'
346+
letter.error_code = 'UNKNOWN_ERROR'
347+
raise ae
340348
for doc in response['request']['documents']:
341349
if doc.get('sent') and response['request_code'] == 200:
342350
note = _('The document was correctly sent by post.<br>The tracking id is %s', doc['send_id'])

0 commit comments

Comments
 (0)