From db8f98b5900f1d0d55d6969ede389483fe736666 Mon Sep 17 00:00:00 2001 From: Joan Martinez Date: Tue, 17 Dec 2024 18:18:54 +0100 Subject: [PATCH] feat: change return error code --- jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py | 4 ++-- jina/serve/runtimes/worker/http_csp_app.py | 4 ++-- jina/serve/runtimes/worker/http_fastapi_app.py | 4 ++-- jina/serve/runtimes/worker/request_handling.py | 3 +-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py b/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py index 76e3c429da7b9..9939ced58acf0 100644 --- a/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py +++ b/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py @@ -41,7 +41,7 @@ def get_fastapi_app( if expose_graphql_endpoint: logger.error(f' GraphQL endpoint is not enabled when using docarray >0.30') with ImportExtensions(required=True): - from fastapi import FastAPI, Response, HTTPException + from fastapi import FastAPI, Response, HTTPException, status as http_status from fastapi.middleware.cors import CORSMiddleware import pydantic from pydantic import Field @@ -216,7 +216,7 @@ async def post(body: input_model, response: Response): status = resp.header.status if status.code == jina_pb2.StatusProto.ERROR: - raise HTTPException(status_code=499, detail=status.description) + raise HTTPException(status_code=http_status.HTTP_500_INTERNAL_SERVER_ERROR, detail=status.description) else: result_dict = resp.to_dict() return result_dict diff --git a/jina/serve/runtimes/worker/http_csp_app.py b/jina/serve/runtimes/worker/http_csp_app.py index a670a0d1d932c..442241f416f07 100644 --- a/jina/serve/runtimes/worker/http_csp_app.py +++ b/jina/serve/runtimes/worker/http_csp_app.py @@ -30,7 +30,7 @@ def get_fastapi_app( """ with ImportExtensions(required=True): import pydantic - from fastapi import FastAPI, HTTPException, Request + from fastapi import FastAPI, HTTPException, Request, status as http_status from fastapi.middleware.cors import CORSMiddleware from pydantic import BaseModel, Field from pydantic.config import BaseConfig, inherit_config @@ -131,7 +131,7 @@ async def process(body) -> output_model: status = resp.header.status if status.code == jina_pb2.StatusProto.ERROR: - raise HTTPException(status_code=499, detail=status.description) + raise HTTPException(status_code=http_status.HTTP_500_INTERNAL_SERVER_ERROR, detail=status.description) else: return output_model(data=resp.docs, parameters=resp.parameters) diff --git a/jina/serve/runtimes/worker/http_fastapi_app.py b/jina/serve/runtimes/worker/http_fastapi_app.py index 889166d8aeb63..edb4c9dba7afa 100644 --- a/jina/serve/runtimes/worker/http_fastapi_app.py +++ b/jina/serve/runtimes/worker/http_fastapi_app.py @@ -33,7 +33,7 @@ def get_fastapi_app( :return: fastapi app """ with ImportExtensions(required=True): - from fastapi import FastAPI, Response, HTTPException + from fastapi import FastAPI, Response, HTTPException, status as http_status import pydantic from fastapi.middleware.cors import CORSMiddleware import os @@ -116,7 +116,7 @@ async def post(body: input_model, response: Response): status = resp.header.status if status.code == jina_pb2.StatusProto.ERROR: - raise HTTPException(status_code=499, detail=status.description) + raise HTTPException(status_code=http_status.HTTP_500_INTERNAL_SERVER_ERROR, detail=status.description) else: if not docarray_v2: docs_response = resp.docs.to_dict() diff --git a/jina/serve/runtimes/worker/request_handling.py b/jina/serve/runtimes/worker/request_handling.py index 450690d33bcdc..97d90fa954372 100644 --- a/jina/serve/runtimes/worker/request_handling.py +++ b/jina/serve/runtimes/worker/request_handling.py @@ -1079,7 +1079,6 @@ def _extract_tracing_context( ) -> Optional['Context']: if self.tracer: from opentelemetry.propagate import extract - context = extract(dict(metadata)) return context @@ -1116,7 +1115,7 @@ async def process_data( if is_generator: result = await self.handle_generator( - requests=requests,tracing_context=tracing_context + requests=requests, tracing_context=tracing_context ) else: result = await self.handle(