@@ -59,9 +59,11 @@ pub async fn ingest(
5959 . iter ( )
6060 . find ( |& ( key, _) | key == STREAM_NAME_HEADER_KEY )
6161 {
62- let str_name = stream_name. to_str ( ) . unwrap ( ) . to_owned ( ) ;
63- super :: logstream:: create_stream_if_not_exists ( str_name. clone ( ) ) . await ;
64- push_logs ( str_name, req, body) . await ?;
62+ let stream_name = stream_name. to_str ( ) . unwrap ( ) . to_owned ( ) ;
63+ if let Err ( e) = super :: logstream:: create_stream_if_not_exists ( & stream_name) . await {
64+ return Err ( PostError :: CreateStream ( e. into ( ) ) ) ;
65+ }
66+ push_logs ( stream_name, req, body) . await ?;
6567 Ok ( HttpResponse :: Ok ( ) . finish ( ) )
6668 } else {
6769 Err ( PostError :: Header ( ParseHeaderError :: MissingStreamName ) )
@@ -167,6 +169,8 @@ pub mod error {
167169 Event ( #[ from] EventError ) ,
168170 #[ error( "Invalid Request" ) ]
169171 Invalid ,
172+ #[ error( "Failed to create stream due to {0}" ) ]
173+ CreateStream ( Box < dyn std:: error:: Error + Send + Sync > ) ,
170174 }
171175
172176 impl actix_web:: ResponseError for PostError {
@@ -175,6 +179,7 @@ pub mod error {
175179 PostError :: Header ( _) => StatusCode :: BAD_REQUEST ,
176180 PostError :: Event ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
177181 PostError :: Invalid => StatusCode :: BAD_REQUEST ,
182+ PostError :: CreateStream ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
178183 }
179184 }
180185
0 commit comments