mirror of
https://github.com/krateng/maloja.git
synced 2025-05-18 15:56:33 +03:00
Generalized exception handling for native API
This commit is contained in:
parent
62208bf668
commit
afc78e75b0
@ -57,6 +57,20 @@ errors = {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def catch_exceptions(func):
|
||||||
|
def protector(*args,**kwargs):
|
||||||
|
try:
|
||||||
|
return func(*args,**kwargs)
|
||||||
|
except Exception as e:
|
||||||
|
for etype in errors:
|
||||||
|
if isinstance(e,etype):
|
||||||
|
errorhandling = errors[etype](e)
|
||||||
|
response.status = errorhandling[0]
|
||||||
|
return errorhandling[1]
|
||||||
|
|
||||||
|
protector.__doc__ = func.__doc__
|
||||||
|
protector.__annotations__ = func.__annotations__
|
||||||
|
return protector
|
||||||
|
|
||||||
|
|
||||||
def add_common_args_to_docstring(filterkeys=False,limitkeys=False,delimitkeys=False,amountkeys=False):
|
def add_common_args_to_docstring(filterkeys=False,limitkeys=False,delimitkeys=False,amountkeys=False):
|
||||||
@ -365,6 +379,7 @@ def track_info_external(artist:Multi[str],**keys):
|
|||||||
|
|
||||||
@api.post("newscrobble")
|
@api.post("newscrobble")
|
||||||
@authenticated_function(alternate=api_key_correct,api=True,pass_auth_result_as='auth_result')
|
@authenticated_function(alternate=api_key_correct,api=True,pass_auth_result_as='auth_result')
|
||||||
|
@catch_exceptions
|
||||||
def post_scrobble(
|
def post_scrobble(
|
||||||
artist:Multi=None,
|
artist:Multi=None,
|
||||||
artists:list=[],
|
artists:list=[],
|
||||||
@ -406,7 +421,7 @@ def post_scrobble(
|
|||||||
# for logging purposes, don't pass values that we didn't actually supply
|
# for logging purposes, don't pass values that we didn't actually supply
|
||||||
rawscrobble = {k:rawscrobble[k] for k in rawscrobble if rawscrobble[k]}
|
rawscrobble = {k:rawscrobble[k] for k in rawscrobble if rawscrobble[k]}
|
||||||
|
|
||||||
try:
|
|
||||||
result = database.incoming_scrobble(
|
result = database.incoming_scrobble(
|
||||||
rawscrobble,
|
rawscrobble,
|
||||||
client='browser' if auth_result.get('doreah_native_auth_check') else auth_result.get('client'),
|
client='browser' if auth_result.get('doreah_native_auth_check') else auth_result.get('client'),
|
||||||
@ -433,13 +448,6 @@ def post_scrobble(
|
|||||||
'desc':"These two fields are meant as alternative methods to submit information. Use of both is discouraged, but works at the moment."}
|
'desc':"These two fields are meant as alternative methods to submit information. Use of both is discouraged, but works at the moment."}
|
||||||
]
|
]
|
||||||
return responsedict
|
return responsedict
|
||||||
except Exception as e:
|
|
||||||
for etype in errors:
|
|
||||||
if isinstance(e,etype):
|
|
||||||
errorhandling = errors[etype](e)
|
|
||||||
response.status = errorhandling[0]
|
|
||||||
return errorhandling[1]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user