@@ -17,21 +17,21 @@ use serde_json;
17
17
18
18
/// Error type description for the `ErrorResponse` event. This type should be returned
19
19
/// for errors that were handled by the function code or framework.
20
- pub const ERROR_TYPE_HANDLED : & str = "Handled" ;
20
+ #[ allow( dead_code) ]
21
+ pub ( crate ) const ERROR_TYPE_HANDLED : & str = "Handled" ;
21
22
/// Error type description for the `ErrorResponse` event. This type is used for unhandled,
22
23
/// unexpcted errors.
23
- pub const ERROR_TYPE_UNHANDLED : & str = "Unhandled" ;
24
+ pub ( crate ) const ERROR_TYPE_UNHANDLED : & str = "Unhandled" ;
25
+ /// Error type for the error responses to the Runtime APIs. In the future, this library
26
+ /// should use a customer-generated error code
27
+ pub const RUNTIME_ERROR_TYPE : & str = "RustRuntimeError" ;
24
28
25
29
/// This object is used to generate requests to the Lambda Runtime APIs.
26
30
/// It is used for both the error response APIs and fail init calls.
27
31
/// custom error types should implement the `RuntimeError` trait and return
28
32
/// this object to be compatible with the APIs.
29
33
#[ derive( Serialize ) ]
30
34
pub struct ErrorResponse {
31
- /// Internal error code to be sent to the Lambda Runtime APIs in the
32
- /// `Lambda-Runtime-Function-Error-Type` header.
33
- #[ serde( skip) ]
34
- pub error_code : String ,
35
35
/// The error message generated by the application.
36
36
#[ serde( rename = "errorMessage" ) ]
37
37
pub error_message : String ,
@@ -59,11 +59,10 @@ impl ErrorResponse {
59
59
///
60
60
/// # Return
61
61
/// A new instance of the `ErrorResponse` object.
62
- fn new ( message : String , err_type : String , code : String ) -> ErrorResponse {
62
+ fn new ( message : String , err_type : String ) -> ErrorResponse {
63
63
let mut err = ErrorResponse {
64
64
error_message : message,
65
65
error_type : err_type,
66
- error_code : code,
67
66
stack_trace : Option :: default ( ) ,
68
67
} ;
69
68
let is_backtrace = env:: var ( "RUST_BACKTRACE" ) ;
@@ -89,7 +88,7 @@ impl ErrorResponse {
89
88
/// # Return
90
89
/// A populated `RuntimeError` object that can be used with the Lambda Runtime API.
91
90
pub fn handled ( message : String ) -> ErrorResponse {
92
- ErrorResponse :: new ( message, ERROR_TYPE_HANDLED . to_owned ( ) , "RuntimeError" . to_owned ( ) )
91
+ ErrorResponse :: new ( message, RUNTIME_ERROR_TYPE . to_owned ( ) )
93
92
}
94
93
95
94
/// Creates a new `RuntimeError` object with the unhandled error type.
@@ -101,7 +100,7 @@ impl ErrorResponse {
101
100
/// # Return
102
101
/// A populated `RuntimeError` object that can be used with the Lambda Runtime API.
103
102
pub fn unhandled ( message : String ) -> ErrorResponse {
104
- ErrorResponse :: new ( message, ERROR_TYPE_UNHANDLED . to_owned ( ) , "RuntimeError" . to_owned ( ) )
103
+ ErrorResponse :: new ( message, RUNTIME_ERROR_TYPE . to_owned ( ) )
105
104
}
106
105
}
107
106
0 commit comments