clamsproject / clams-python

CLAMS SDK for python
http://sdk.clams.ai/
Apache License 2.0
4 stars 1 forks source link

Applications returning XML instead of JSON #91

Closed marcverhagen closed 1 year ago

marcverhagen commented 2 years ago

It would be nice if a post request to any application is guaranteed to return JSON. It does not if you hand in an unknown parameter, due to the following code on clams.ClamsHTTPApi.

def post(self) -> Response:
    in_mmif = Mmif(request.get_data())
    params = self.annotate_param_caster.cast(request.args)
    try:
        return self.json_to_response(self.cla.annotate(in_mmif, **params))
    except Exception as e:
        return self.json_to_response(self.cla.record_error(in_mmif, params).serialize(pretty=True), status=500)

When self.annotate_param_caster.cast(request.args) is given an undefined parameter it throws an error and that error is wrapped in a large XML structure by Flask/Werkzeug. We should either not throw an error or catch that error like we do with exceptions raised by annotate method.

keighrim commented 1 year ago

This should be fixed by now via #106 . Closing for now.