bryokim / bible-api

Get bible verses
https://bible-api-ew0i.onrender.com/
MIT License
0 stars 0 forks source link

fix: handle missing verses #1

Closed bryokim closed 7 months ago

bryokim commented 7 months ago

Error message:

Traceback (most recent call last):
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py", line 407, in run_asgi
[1]     result = await app(  # type: ignore[func-returns-value]
[1]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
[1]     return await self.app(scope, receive, send)
[1]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
[1]     await super().__call__(scope, receive, send)
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/starlette/applications.py", line 123, in __call__
[1]     await self.middleware_stack(scope, receive, send)
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/starlette/middleware/errors.py", line 186, in __call__
[1]     raise exc
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/starlette/middleware/errors.py", line 164, in __call__
[1]     await self.app(scope, receive, _send)
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
[1]     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
[1]     raise exc
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
[1]     await app(scope, receive, sender)
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 758, in __call__
[1]     await self.middleware_stack(scope, receive, send)
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 778, in app
[1]     await route.handle(scope, receive, send)
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 299, in handle
[1]     await self.app(scope, receive, send)
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 79, in app
[1]     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
[1]     raise exc
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
[1]     await app(scope, receive, sender)
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/starlette/routing.py", line 74, in app
[1]     response = await func(request)
[1]                ^^^^^^^^^^^^^^^^^^^
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/fastapi/routing.py", line 278, in app
[1]     raw_response = await run_endpoint_function(
[1]                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
[1]     return await dependant.call(**values)
[1]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1]   File "/home/briankim/Dev/big-league/holy-text/api/bible/router.py", line 61, in random_verse
[1]     full_verse, verse_text = get_random_verse(
[1]                              ^^^^^^^^^^^^^^^^^
[1]   File "/home/briankim/Dev/big-league/holy-text/api/bible/service.py", line 76, in get_random_verse
[1]     (_, _), verse_text = get_parsed_verse(full_verse, bible_version)
[1]                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1]   File "/home/briankim/Dev/big-league/holy-text/api/bible/service.py", line 49, in get_parsed_verse
[1]     text = get_verse_text(verse, bible_version=bible_version)
[1]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1]   File "/home/briankim/Dev/big-league/holy-text/api/bible/service.py", line 10, in get_verse_text
[1]     text = bible.format_scripture_text(
[1]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/pythonbible/formatter.py", line 389, in format_scripture_text
[1]     verse_text = bible.get_scripture(current_start_verse, current_end_verse)
[1]                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/pythonbible/bible/bible.py", line 62, in get_scripture
[1]     start_index, end_index = self._get_start_and_end_indices(
[1]                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1]   File "/home/briankim/.cache/pypoetry/virtualenvs/holy-text-sR2s3zvh-py3.12/lib/python3.12/site-packages/pythonbible/bible/bible.py", line 77, in _get_start_and_end_indices
[1]     raise VersionMissingVerseError(self.version.value, start_verse_id)
[1] pythonbible.errors.VersionMissingVerseError: NIV is missing verse 69018020.

Missing verses should be noted when encountered and added if possible. An error message should be sent to the client on first encounter informing them of the missing verse.

bryokim commented 7 months ago

Getting books from not available in the given version caused the error