16
16
*
17
17
*/
18
18
19
- use std:: sync:: Arc ;
20
-
21
19
use actix_web:: http:: header:: ContentType ;
22
20
use actix_web:: { HttpRequest , HttpResponse } ;
23
21
use arrow_schema:: Schema ;
@@ -29,6 +27,7 @@ use crate::event::error::EventError;
29
27
use crate :: event:: format:: EventFormat ;
30
28
use crate :: event:: { self , format} ;
31
29
use crate :: handlers:: { PREFIX_META , PREFIX_TAGS , SEPARATOR , STREAM_NAME_HEADER_KEY } ;
30
+ use crate :: metadata:: error:: stream_info:: MetadataError ;
32
31
use crate :: metadata:: STREAM_INFO ;
33
32
use crate :: utils:: header_parsing:: { collect_labelled_headers, ParseHeaderError } ;
34
33
@@ -62,7 +61,8 @@ pub async fn post_event(req: HttpRequest, body: Bytes) -> Result<HttpResponse, P
62
61
}
63
62
64
63
async fn push_logs ( stream_name : String , req : HttpRequest , body : Bytes ) -> Result < ( ) , PostError > {
65
- let ( size, rb) = into_event_batch ( req, body, & get_stream_schema ( & stream_name) ) ?;
64
+ let schema = STREAM_INFO . schema ( & stream_name) ?;
65
+ let ( size, rb) = into_event_batch ( req, body, & schema) ?;
66
66
67
67
event:: Event {
68
68
rb,
@@ -95,12 +95,10 @@ fn into_event_batch(
95
95
Ok ( ( size, rb) )
96
96
}
97
97
98
- fn get_stream_schema ( stream_name : & str ) -> Arc < Schema > {
99
- STREAM_INFO . schema ( stream_name) . unwrap ( )
100
- }
101
-
102
98
#[ derive( Debug , thiserror:: Error ) ]
103
99
pub enum PostError {
100
+ #[ error( "{0}" ) ]
101
+ StreamNotFound ( #[ from] MetadataError ) ,
104
102
#[ error( "Could not deserialize into JSON object, {0}" ) ]
105
103
SerdeError ( #[ from] serde_json:: Error ) ,
106
104
#[ error( "Header Error: {0}" ) ]
@@ -121,6 +119,7 @@ impl actix_web::ResponseError for PostError {
121
119
PostError :: Event ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
122
120
PostError :: Invalid ( _) => StatusCode :: BAD_REQUEST ,
123
121
PostError :: CreateStream ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
122
+ PostError :: StreamNotFound ( _) => StatusCode :: NOT_FOUND ,
124
123
}
125
124
}
126
125
0 commit comments