[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/odoo#84263 X-original-commit: b3c46e8050e9405e69cfbe9c49706a22007e10ba Signed-off-by: Florian Daloze (fda) <fda@odoo.com> Signed-off-by: Zians Dominik (dozi) <dozi@odoo.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import base64
|
||||
|
||||
from odoo import fields, models, api, _
|
||||
from odoo.addons.iap.tools import iap_tools
|
||||
from odoo.exceptions import AccessError
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
DEFAULT_ENDPOINT = 'https://iap-snailmail.odoo.com'
|
||||
@@ -342,7 +343,14 @@ class SnailmailLetter(models.Model):
|
||||
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 = iap_tools.iap_jsonrpc(endpoint + PRINT_ENDPOINT, params=params, timeout=timeout)
|
||||
try:
|
||||
response = iap_tools.iap_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:
|
||||
self.env['iap.account']._send_iap_bus_notification(
|
||||
|
||||
Reference in New Issue
Block a user