diff --git a/nanopub_submitter/api.py b/nanopub_submitter/api.py index a113864..97cb023 100644 --- a/nanopub_submitter/api.py +++ b/nanopub_submitter/api.py @@ -96,7 +96,7 @@ async def submit_nanopub(request: fastapi.Request): LOG.error(f'[{submission_id}] Unexpected processing error: {str(e)}') return fastapi.responses.PlainTextResponse( status_code=fastapi.status.HTTP_500_INTERNAL_SERVER_ERROR, - content='Failed to process the nanopublication', + content=f'Failed to process the nanopublication: {str(e)}', ) # (4) Mail Mailer.get().notice(nanopub_uri=result.location) diff --git a/nanopub_submitter/nanopub.py b/nanopub_submitter/nanopub.py index 0f357f3..7df351f 100644 --- a/nanopub_submitter/nanopub.py +++ b/nanopub_submitter/nanopub.py @@ -120,20 +120,25 @@ def _publish_nanopub(nanopub_bundle: str, ctx: NanopubProcessingContext) -> list ctx.debug(f'Submitting to: {server}') ok = True for nanopub in nanopubs: - r = requests.post( - url=server, - data=nanopub, - headers={ - 'Content-Type': f'application/trig; charset={DEFAULT_ENCODING}', - 'User-Agent': f'{PACKAGE_NAME}/{PACKAGE_VERSION}', - }, - timeout=10, - ) - if not r.ok: + try: + r = requests.post( + url=server, + data=nanopub.encode(encoding=DEFAULT_ENCODING), + headers={ + 'Content-Type': f'application/trig; charset={DEFAULT_ENCODING}', + 'User-Agent': f'{PACKAGE_NAME}/{PACKAGE_VERSION}', + }, + timeout=10, + ) + if not r.ok: + ok = False + ctx.warn(f'Failed to publish nanopub via {server}') + ctx.debug(f'status={r.status_code}') + ctx.debug(r.text) + break + except Exception as e: ok = False - ctx.warn(f'Failed to publish nanopub via {server}') - ctx.debug(f'status={r.status_code}') - ctx.debug(r.text) + ctx.warn(f'Failed to publish nanopub via {server}: {str(e)}') break if ok: ctx.info(f'Nanopub published via {server}')