@@ -82,6 +82,8 @@ def format_exception_content(
82
82
instance = instance ,
83
83
trace_id = structlog .contextvars .get_contextvars ().get ("trace_id" , "unset" ),
84
84
).model_dump (exclude_none = True )
85
+ if isinstance (exc , ogc_api_processes_fastapi .exceptions .JobResultsFailed ):
86
+ exception_content ["traceback" ] = exc .traceback
85
87
86
88
return exception_content
87
89
@@ -108,10 +110,11 @@ def exception_handler(
108
110
exception = "" .join (traceback .TracebackException .from_exception (exc ).format ()),
109
111
url = str (request .url ),
110
112
)
111
- return fastapi .responses .JSONResponse (
113
+ out = fastapi .responses .JSONResponse (
112
114
status_code = exc .status_code ,
113
115
content = format_exception_content (exc = exc , request = request ),
114
116
)
117
+ return out
115
118
116
119
117
120
def request_readtimeout_handler (
@@ -137,8 +140,7 @@ def request_readtimeout_handler(
137
140
type = "read timeout error" ,
138
141
title = "read timeout error" ,
139
142
trace_id = structlog .contextvars .get_contextvars ().get ("trace_id" , "unset" ),
140
- detail = str (exc ),
141
- ),
143
+ ).model_dump (exclude_none = True ),
142
144
)
143
145
return out
144
146
@@ -165,14 +167,15 @@ def general_exception_handler(
165
167
"internal server error" ,
166
168
exception = "" .join (traceback .TracebackException .from_exception (exc ).format ()),
167
169
)
168
- return fastapi .responses .JSONResponse (
170
+ out = fastapi .responses .JSONResponse (
169
171
status_code = fastapi .status .HTTP_500_INTERNAL_SERVER_ERROR ,
170
172
content = models .Exception (
171
173
type = "internal server error" ,
172
174
title = "internal server error" ,
173
175
trace_id = structlog .contextvars .get_contextvars ().get ("trace_id" , "unset" ),
174
176
).model_dump (exclude_none = True ),
175
177
)
178
+ return out
176
179
177
180
178
181
def include_exception_handlers (app : fastapi .FastAPI ) -> fastapi .FastAPI :
@@ -193,6 +196,9 @@ def include_exception_handlers(app: fastapi.FastAPI) -> fastapi.FastAPI:
193
196
app .add_exception_handler (InvalidParameter , exception_handler ) # type: ignore
194
197
app .add_exception_handler (InvalidRequest , exception_handler ) # type: ignore
195
198
app .add_exception_handler (JobResultsExpired , exception_handler ) # type: ignore
196
- app .add_exception_handler (requests .exceptions .ReadTimeout , exception_handler ) # type: ignore
199
+ app .add_exception_handler (
200
+ requests .exceptions .ReadTimeout ,
201
+ request_readtimeout_handler , # type: ignore
202
+ )
197
203
app .add_exception_handler (Exception , general_exception_handler )
198
204
return app
0 commit comments