@@ -17,21 +17,21 @@ use serde_json;
1717
1818/// Error type description for the `ErrorResponse` event. This type should be returned
1919/// 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" ;
2122/// Error type description for the `ErrorResponse` event. This type is used for unhandled,
2223/// 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" ;
2428
2529/// This object is used to generate requests to the Lambda Runtime APIs.
2630/// It is used for both the error response APIs and fail init calls.
2731/// custom error types should implement the `RuntimeError` trait and return
2832/// this object to be compatible with the APIs.
2933#[ derive( Serialize ) ]
3034pub 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 ,
3535 /// The error message generated by the application.
3636 #[ serde( rename = "errorMessage" ) ]
3737 pub error_message : String ,
@@ -59,11 +59,10 @@ impl ErrorResponse {
5959 ///
6060 /// # Return
6161 /// 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 {
6363 let mut err = ErrorResponse {
6464 error_message : message,
6565 error_type : err_type,
66- error_code : code,
6766 stack_trace : Option :: default ( ) ,
6867 } ;
6968 let is_backtrace = env:: var ( "RUST_BACKTRACE" ) ;
@@ -89,7 +88,7 @@ impl ErrorResponse {
8988 /// # Return
9089 /// A populated `RuntimeError` object that can be used with the Lambda Runtime API.
9190 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 ( ) )
9392 }
9493
9594 /// Creates a new `RuntimeError` object with the unhandled error type.
@@ -101,7 +100,7 @@ impl ErrorResponse {
101100 /// # Return
102101 /// A populated `RuntimeError` object that can be used with the Lambda Runtime API.
103102 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 ( ) )
105104 }
106105}
107106
0 commit comments