@@ -16,6 +16,8 @@ pub enum MediaError {
1616 ImageTooLarge ,
1717 #[ error( "invalid image data" ) ]
1818 InvalidImage ,
19+ #[ error( "media contains metadata or a non-canonical metadata channel" ) ]
20+ MetadataForbidden ,
1921 #[ error( "invalid signature" ) ]
2022 InvalidSignature ,
2123 #[ error( "invalid auth event kind" ) ]
@@ -60,8 +62,8 @@ pub enum MediaError {
6062 UploadRateLimitExceeded ,
6163 #[ error( "upload concurrency limit reached" ) ]
6264 UploadConcurrencyLimitReached ,
63- /// Video codec is not H.264 (avc1) .
64- #[ error( "unsupported video codec: only H.264 (avc1) is accepted" ) ]
65+ /// A video/audio track does not use the canonical H.264/AAC codecs .
66+ #[ error( "unsupported media codec: only H.264 video and AAC audio are accepted" ) ]
6567 WrongCodec ,
6668 /// Video duration exceeds the 600-second limit.
6769 #[ error( "video too long: duration exceeds 600 seconds" ) ]
@@ -140,15 +142,15 @@ impl IntoResponse for MediaError {
140142 Self :: UploadRateLimitExceeded | Self :: UploadConcurrencyLimitReached => {
141143 ( StatusCode :: TOO_MANY_REQUESTS , self . to_string ( ) )
142144 }
143- Self :: UnsupportedContainer => ( StatusCode :: UNSUPPORTED_MEDIA_TYPE , self . to_string ( ) ) ,
144- Self :: WrongCodec
145- | Self :: DurationTooLong
145+ Self :: UnknownContentType | Self :: UnsupportedContainer | Self :: WrongCodec => {
146+ ( StatusCode :: UNSUPPORTED_MEDIA_TYPE , self . to_string ( ) )
147+ }
148+ Self :: DurationTooLong
146149 | Self :: ResolutionTooHigh
147150 | Self :: MoovNotAtFront
148- | Self :: InvalidVideo => ( StatusCode :: BAD_REQUEST , self . to_string ( ) ) ,
149- Self :: UnknownContentType | Self :: InvalidImage => {
150- ( StatusCode :: BAD_REQUEST , self . to_string ( ) )
151- }
151+ | Self :: InvalidVideo
152+ | Self :: InvalidImage
153+ | Self :: MetadataForbidden => ( StatusCode :: UNPROCESSABLE_ENTITY , self . to_string ( ) ) ,
152154 Self :: Io ( _) | Self :: StorageError ( _) | Self :: Internal => {
153155 tracing:: error!( error = %self , "media storage error" ) ;
154156 ( StatusCode :: INTERNAL_SERVER_ERROR , "internal error" . into ( ) )
@@ -157,3 +159,40 @@ impl IntoResponse for MediaError {
157159 ( status, axum:: Json ( serde_json:: json!( { "error" : msg} ) ) ) . into_response ( )
158160 }
159161}
162+
163+ #[ cfg( test) ]
164+ mod tests {
165+ use super :: * ;
166+
167+ #[ test]
168+ fn unsupported_media_maps_to_415 ( ) {
169+ for error in [
170+ MediaError :: UnknownContentType ,
171+ MediaError :: DisallowedContentType ( "audio/mpeg" . to_string ( ) ) ,
172+ MediaError :: UnsupportedContainer ,
173+ MediaError :: WrongCodec ,
174+ ] {
175+ assert_eq ! (
176+ error. into_response( ) . status( ) ,
177+ StatusCode :: UNSUPPORTED_MEDIA_TYPE
178+ ) ;
179+ }
180+ }
181+
182+ #[ test]
183+ fn invalid_or_noncanonical_media_maps_to_422 ( ) {
184+ for error in [
185+ MediaError :: InvalidImage ,
186+ MediaError :: InvalidVideo ,
187+ MediaError :: MetadataForbidden ,
188+ MediaError :: MoovNotAtFront ,
189+ MediaError :: DurationTooLong ,
190+ MediaError :: ResolutionTooHigh ,
191+ ] {
192+ assert_eq ! (
193+ error. into_response( ) . status( ) ,
194+ StatusCode :: UNPROCESSABLE_ENTITY
195+ ) ;
196+ }
197+ }
198+ }
0 commit comments