Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added optional callback SqlalchemyDataLayer.unhandled_exception_forma… #149

Closed

Conversation

tadams42
Copy link

Related to #72

I'd introduced another optional argument for SQLAlchemy data layer that works like this:

def sa_exception_formatter(exc):
    return {"detail": "SQLAlchemy complains!", "status": 405}

class ComputerList(ResourceList):
    schema = ComputerSchema
    data_layer = {'session': db.session,
                  'model': Computer,
                  'unhandled_exception_formatter': sa_exception_formatter}

I was playing with idea to generalize this more, but after inspecting existing code, I don't think it is needed - in 99% cases flask-rest-jsonapi already does the only sane thing.

So, this new callback gets (optionally) called only in places where unexpected exception had happened.

What do you think?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 91.408% when pulling a8e5e3f on tadams42:custom_sa_data_layer_exceptions into ecc8f2c on miLibris:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 91.408% when pulling a8e5e3f on tadams42:custom_sa_data_layer_exceptions into ecc8f2c on miLibris:master.

@coveralls
Copy link

coveralls commented Apr 29, 2019

Coverage Status

Coverage increased (+0.09%) to 91.132% when pulling 72e978c on tadams42:custom_sa_data_layer_exceptions into b4cb557 on miLibris:master.

@tadams42 tadams42 force-pushed the custom_sa_data_layer_exceptions branch from a8e5e3f to 72e978c Compare May 20, 2019 07:11
@tadams42 tadams42 closed this May 29, 2021
@tadams42 tadams42 deleted the custom_sa_data_layer_exceptions branch May 29, 2021 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants