Qurrah commited on
Commit
4e345df
·
1 Parent(s): ba413f2

REFINE: standardize error response structure by changing 'message' to 'detail'

Browse files
Files changed (1) hide show
  1. api/errors.py +7 -11
api/errors.py CHANGED
@@ -15,7 +15,7 @@ def add_exception_handlers(app):
15
  logger.warning(f"Rate limit exceeded on {request.url.path}")
16
  return JSONResponse(
17
  status_code=429,
18
- content={"status": "error", "message": str(exc)},
19
  )
20
 
21
  @app.exception_handler(BaseAppException)
@@ -27,7 +27,7 @@ def add_exception_handlers(app):
27
 
28
  return JSONResponse(
29
  status_code=exc.status_code,
30
- content={"status": "error", "message": exc.message},
31
  )
32
 
33
  @app.exception_handler(Timeout)
@@ -35,7 +35,7 @@ def add_exception_handlers(app):
35
  logger.error(f"Shopify timeout on {request.url.path}")
36
  return JSONResponse(
37
  status_code=504,
38
- content={"status": "error", "message": "External service timed out"},
39
  )
40
 
41
  @app.exception_handler(ConnectionError)
@@ -43,7 +43,7 @@ def add_exception_handlers(app):
43
  logger.error(f"Connection error on {request.url.path}")
44
  return JSONResponse(
45
  status_code=502,
46
- content={"status": "error", "message": "Could not connect to external service"},
47
  )
48
 
49
  @app.exception_handler(HTTPError)
@@ -51,7 +51,7 @@ def add_exception_handlers(app):
51
  logger.error(f"HTTP error on {request.url.path}: {exc}")
52
  return JSONResponse(
53
  status_code=400,
54
- content={"status": "error", "message": f"External service error: {str(exc)}"},
55
  )
56
 
57
  @app.exception_handler(ValueError)
@@ -59,7 +59,7 @@ def add_exception_handlers(app):
59
  logger.warning(f"Value error on {request.url.path}: {exc}")
60
  return JSONResponse(
61
  status_code=400,
62
- content={"status": "error", "message": str(exc)},
63
  )
64
 
65
  @app.exception_handler(Exception)
@@ -67,9 +67,5 @@ def add_exception_handlers(app):
67
  logger.error(f"Unhandled exception on {request.url.path}: {exc}", exc_info=True)
68
  return JSONResponse(
69
  status_code=500,
70
- content={
71
- "status": "error",
72
- "message": "Internal server error",
73
- "detail": str(exc) if not isinstance(exc, RuntimeError) else "Something went wrong",
74
- },
75
  )
 
15
  logger.warning(f"Rate limit exceeded on {request.url.path}")
16
  return JSONResponse(
17
  status_code=429,
18
+ content={"status": "error", "detail": str(exc)},
19
  )
20
 
21
  @app.exception_handler(BaseAppException)
 
27
 
28
  return JSONResponse(
29
  status_code=exc.status_code,
30
+ content={"status": "error", "detail": exc.message},
31
  )
32
 
33
  @app.exception_handler(Timeout)
 
35
  logger.error(f"Shopify timeout on {request.url.path}")
36
  return JSONResponse(
37
  status_code=504,
38
+ content={"status": "error", "detail": "External service timed out"},
39
  )
40
 
41
  @app.exception_handler(ConnectionError)
 
43
  logger.error(f"Connection error on {request.url.path}")
44
  return JSONResponse(
45
  status_code=502,
46
+ content={"status": "error", "detail": "Could not connect to external service"},
47
  )
48
 
49
  @app.exception_handler(HTTPError)
 
51
  logger.error(f"HTTP error on {request.url.path}: {exc}")
52
  return JSONResponse(
53
  status_code=400,
54
+ content={"status": "error", "detail": f"External service error: {str(exc)}"},
55
  )
56
 
57
  @app.exception_handler(ValueError)
 
59
  logger.warning(f"Value error on {request.url.path}: {exc}")
60
  return JSONResponse(
61
  status_code=400,
62
+ content={"status": "error", "detail": str(exc)},
63
  )
64
 
65
  @app.exception_handler(Exception)
 
67
  logger.error(f"Unhandled exception on {request.url.path}: {exc}", exc_info=True)
68
  return JSONResponse(
69
  status_code=500,
70
+ content={"status": "error", "detail": "Internal server error"},
 
 
 
 
71
  )