1
+ use chirp_workflow:: prelude:: WorkflowError ;
1
2
use chrono:: TimeZone ;
2
3
use global_error:: prelude:: * ;
3
4
use headers:: HeaderValue ;
@@ -26,6 +27,14 @@ pub fn handle_rejection(
26
27
mut response : http:: response:: Builder ,
27
28
ray_id : Uuid ,
28
29
) -> Result < Response < Body > , http:: Error > {
30
+ // TODO: Remove panic
31
+ let verbose_errors = config
32
+ . server ( )
33
+ . expect ( "missing server" )
34
+ . rivet
35
+ . api_public
36
+ . verbose_errors ( ) ;
37
+
29
38
// Log error
30
39
let err = match err {
31
40
GlobalError :: BadRequest { .. } => {
@@ -37,36 +46,43 @@ pub fn handle_rejection(
37
46
38
47
// Replace internal errors with global errors
39
48
// TODO: Remove panic
40
- if config
41
- . server ( )
42
- . expect ( "missing server" )
43
- . rivet
44
- . api_public
45
- . verbose_errors ( )
46
- {
49
+ if verbose_errors {
47
50
err_code ! ( ERROR , error = err. to_string( ) )
48
51
} else {
49
52
err_code ! ( ERROR , error = "An internal error has occurred." , )
50
53
}
51
54
}
52
55
GlobalError :: Raw ( err) => {
53
- tracing:: error!( ?err, "internal error response" ) ;
56
+ // Check if this is a workflow error that wraps a global error
57
+ match err. downcast :: < WorkflowError > ( ) . map ( |x| * x) {
58
+ Ok ( WorkflowError :: OperationFailure ( global_err) ) => {
59
+ // Handle unwrapped error
60
+ return handle_rejection ( config, global_err, response, ray_id) ;
61
+ }
62
+ Ok ( err) => {
63
+ tracing:: error!( ?err, "internal error response" ) ;
54
64
55
- // Replace internal errors with global errors
56
- // TODO: Remove panic
57
- if config
58
- . server ( )
59
- . expect ( "missing server" )
60
- . rivet
61
- . api_public
62
- . verbose_errors ( )
63
- {
64
- err_code ! ( ERROR , error = err. to_string( ) )
65
- } else {
66
- err_code ! (
67
- ERROR ,
68
- error = format!( "An internal error has occurred (ray_id {})." , ray_id)
69
- )
65
+ if verbose_errors {
66
+ err_code ! ( ERROR , error = err. to_string( ) )
67
+ } else {
68
+ err_code ! (
69
+ ERROR ,
70
+ error = format!( "An internal error has occurred (ray_id {})." , ray_id)
71
+ )
72
+ }
73
+ }
74
+ Err ( err) => {
75
+ tracing:: error!( ?err, "internal error response" ) ;
76
+
77
+ if verbose_errors {
78
+ err_code ! ( ERROR , error = err. to_string( ) )
79
+ } else {
80
+ err_code ! (
81
+ ERROR ,
82
+ error = format!( "An internal error has occurred (ray_id {})." , ray_id)
83
+ )
84
+ }
85
+ }
70
86
}
71
87
}
72
88
} ;
0 commit comments