Completed
Push — master ( 8b994f...9110cc )
by George
01:21
created

SQSMessageTranslator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %
Metric Value
dl 0
loc 14
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A translate() 0 12 3
1
# -*- coding: utf-8 -*-
2
# vi:si:et:sw=4:sts=4:ts=4
3
4
import json
5
import logging
6
7
from ..message_translator import StringMessageTranslator
8
9
logger = logging.getLogger(__name__)
10
11
12
class SQSMessageTranslator(StringMessageTranslator):
13
14
    def translate(self, message):
15
        try:
16
            body = message['Body']
17
        except (KeyError, TypeError):
18
            logger.error('Missing Body key in SQS message. It really came from SQS ?')
19
            return {'content': None}
20
21
        try:
22
            return {'content': json.loads(body)}
23
        except json.decoder.JSONDecodeError as exc:
24
            logger.exception(exc)
25
            return {'content': None}
26