Skip to content

Commit

Permalink
feat(ext): improve error message for db decryption error (#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonadoni committed Nov 22, 2024
1 parent 8c01d51 commit bbab1bf
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions reana_server/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
from flask_limiter.errors import RateLimitExceeded
from marshmallow.exceptions import ValidationError
from reana_commons.config import REANA_LOG_FORMAT, REANA_LOG_LEVEL
from sqlalchemy_utils.types.encrypted.padding import InvalidPaddingError
from werkzeug.exceptions import UnprocessableEntity


from reana_server import config


Expand Down Expand Up @@ -52,6 +54,17 @@ def handle_args_validation_error(error: UnprocessableEntity):
return jsonify({"message": error_message}), 400


def handle_invalid_padding_error(error: InvalidPaddingError):
"""Error handler for sqlalchemy_utils exception ``InvalidPaddingError``.
This error handler raises an exception with a more understandable message.
"""
raise InvalidPaddingError(
"Error decrypting the database. Did you set the correct secret key? "
"If you changed the secret key, did you run the migration command?"
) from error


class REANA(object):
"""REANA Invenio app."""

Expand Down Expand Up @@ -103,3 +116,4 @@ def init_error_handlers(self, app):
"""Initialize custom error handlers."""
app.register_error_handler(RateLimitExceeded, handle_rate_limit_error)
app.register_error_handler(UnprocessableEntity, handle_args_validation_error)
app.register_error_handler(InvalidPaddingError, handle_invalid_padding_error)

0 comments on commit bbab1bf

Please sign in to comment.