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

error handlers #288

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ class InvenioRecordResourceConfigBuilder(InvenioBaseClassPythonBuilder):
TYPE = "invenio_record_resource_config"
section = "resource-config"
template = "resource-config"

def finish(self, **extra_kwargs):
profile = self.current_model.profile
super().finish(profile=profile, **extra_kwargs)
10 changes: 10 additions & 0 deletions oarepo_model_builder/invenio/templates/resource_config.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,14 @@ class {{ vars.resource_config|class_header }}:
**entrypoint_response_handlers
}

@property
def error_handlers(self):
entrypoint_error_handlers = {}
for x in importlib_metadata.entry_points(group='invenio.{{ vars.module.qualified }}_{{ profile }}.error_handlers'):
entrypoint_error_handlers.update(x.load())
return {
**super().error_handlers,
**entrypoint_error_handlers
}

{{ vars.resource_config|extra_code }}
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-model-builder
version = 4.0.101
version = 4.0.102
description = A utility library that generates OARepo required data model files from a JSON specification file
authors = Miroslav Bauer <[email protected]>, Miroslav Simek <[email protected]>
readme = README.md
Expand Down
12 changes: 11 additions & 1 deletion tests/test_simple_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def test_resource_config_builder():
[InvenioRecordResourceConfigBuilder],
os.path.join("test", "resources", "records", "config.py"),
)

print(data)
assert strip_whitespaces(data) == strip_whitespaces(
'''
import importlib_metadata
Expand All @@ -349,6 +349,16 @@ def response_handlers(self):
**super().response_handlers,
**entrypoint_response_handlers
}

@property
def error_handlers(self):
entrypoint_error_handlers = {}
for x in importlib_metadata.entry_points(group='invenio.test_record.error_handlers'):
entrypoint_error_handlers.update(x.load())
return {
**super().error_handlers,
**entrypoint_error_handlers
}
'''
)

Expand Down
Loading