File size: 523 Bytes
7387da9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from bottle import response
import logging


def error_plugin(callback):
    """

    Bottle plugin to handle exceptions

    https://stackoverflow.com/a/32764250

    """

    def wrapper(*args, **kwargs):
        try:
            actual_response = callback(*args, **kwargs)
        except Exception as e:
            logging.error(str(e))
            actual_response = {
                "error": str(e)
            }
            response.status = 500
        return actual_response

    return wrapper