Skip to content

Commit

Permalink
error handlers (#288)
Browse files Browse the repository at this point in the history
* error handlers

* entrypoint for each profile

* imports

---------

Co-authored-by: Alzbeta Pokorna <[email protected]>
  • Loading branch information
Alzpeta and Alzbeta Pokorna authored Jan 20, 2025
1 parent 863cec9 commit ca77a0e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
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

0 comments on commit ca77a0e

Please sign in to comment.