@@ -59,9 +59,11 @@ pub async fn ingest(
59
59
. iter ( )
60
60
. find ( |& ( key, _) | key == STREAM_NAME_HEADER_KEY )
61
61
{
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 ?;
65
67
Ok ( HttpResponse :: Ok ( ) . finish ( ) )
66
68
} else {
67
69
Err ( PostError :: Header ( ParseHeaderError :: MissingStreamName ) )
@@ -167,6 +169,8 @@ pub mod error {
167
169
Event ( #[ from] EventError ) ,
168
170
#[ error( "Invalid Request" ) ]
169
171
Invalid ,
172
+ #[ error( "Failed to create stream due to {0}" ) ]
173
+ CreateStream ( Box < dyn std:: error:: Error + Send + Sync > ) ,
170
174
}
171
175
172
176
impl actix_web:: ResponseError for PostError {
@@ -175,6 +179,7 @@ pub mod error {
175
179
PostError :: Header ( _) => StatusCode :: BAD_REQUEST ,
176
180
PostError :: Event ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
177
181
PostError :: Invalid => StatusCode :: BAD_REQUEST ,
182
+ PostError :: CreateStream ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
178
183
}
179
184
}
180
185
0 commit comments