2021-11-08 18:31:27 +01:00
use std ::error ::Error ;
2022-06-06 12:38:46 +02:00
use meilisearch_types ::error ::{ Code , ErrorCode } ;
use meilisearch_types ::internal_error ;
2021-11-08 18:31:27 +01:00
use serde_json ::Value ;
pub type Result < T > = std ::result ::Result < T , AuthControllerError > ;
#[ derive(Debug, thiserror::Error) ]
pub enum AuthControllerError {
#[ error( " `{0}` field is mandatory. " ) ]
MissingParameter ( & 'static str ) ,
2022-02-14 15:32:41 +01:00
#[ error( " `actions` field value `{0}` is invalid. It should be an array of string representing action names. " ) ]
2021-11-08 18:31:27 +01:00
InvalidApiKeyActions ( Value ) ,
2022-02-14 15:32:41 +01:00
#[ error( " `indexes` field value `{0}` is invalid. It should be an array of string representing index names. " ) ]
2021-11-08 18:31:27 +01:00
InvalidApiKeyIndexes ( Value ) ,
2022-02-14 15:32:41 +01:00
#[ error( " `expiresAt` field value `{0}` is invalid. It should follow the RFC 3339 format to represents a date or datetime in the future or specified as a null value. e.g. 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'. " ) ]
2021-11-08 18:31:27 +01:00
InvalidApiKeyExpiresAt ( Value ) ,
2022-02-14 15:32:41 +01:00
#[ error( " `description` field value `{0}` is invalid. It should be a string or specified as a null value. " ) ]
2021-11-08 18:31:27 +01:00
InvalidApiKeyDescription ( Value ) ,
2022-05-25 10:32:47 +02:00
#[ error(
" `name` field value `{0}` is invalid. It should be a string or specified as a null value. "
) ]
InvalidApiKeyName ( Value ) ,
2022-06-01 14:11:56 +02:00
#[ error( " `uid` field value `{0}` is invalid. It should be a valid UUID v4 string or omitted. " ) ]
2022-05-25 10:32:47 +02:00
InvalidApiKeyUid ( Value ) ,
2021-11-08 18:31:27 +01:00
#[ error( " API key `{0}` not found. " ) ]
ApiKeyNotFound ( String ) ,
2022-06-01 14:11:56 +02:00
#[ error( " `uid` field value `{0}` is already an existing API key. " ) ]
2022-05-25 10:32:47 +02:00
ApiKeyAlreadyExists ( String ) ,
2022-06-02 11:11:07 +02:00
#[ error( " The `{0}` field cannot be modified for the given resource. " ) ]
2022-06-01 14:11:56 +02:00
ImmutableField ( String ) ,
2021-11-08 18:31:27 +01:00
#[ error( " Internal error: {0} " ) ]
Internal ( Box < dyn Error + Send + Sync + 'static > ) ,
}
2021-12-06 15:45:41 +01:00
internal_error! (
2022-03-16 13:45:58 +01:00
AuthControllerError : milli ::heed ::Error ,
2021-12-06 15:45:41 +01:00
std ::io ::Error ,
serde_json ::Error ,
std ::str ::Utf8Error
) ;
2021-11-08 18:31:27 +01:00
impl ErrorCode for AuthControllerError {
fn error_code ( & self ) -> Code {
match self {
Self ::MissingParameter ( _ ) = > Code ::MissingParameter ,
Self ::InvalidApiKeyActions ( _ ) = > Code ::InvalidApiKeyActions ,
Self ::InvalidApiKeyIndexes ( _ ) = > Code ::InvalidApiKeyIndexes ,
Self ::InvalidApiKeyExpiresAt ( _ ) = > Code ::InvalidApiKeyExpiresAt ,
Self ::InvalidApiKeyDescription ( _ ) = > Code ::InvalidApiKeyDescription ,
2022-05-25 10:32:47 +02:00
Self ::InvalidApiKeyName ( _ ) = > Code ::InvalidApiKeyName ,
2021-11-08 18:31:27 +01:00
Self ::ApiKeyNotFound ( _ ) = > Code ::ApiKeyNotFound ,
2022-05-25 10:32:47 +02:00
Self ::InvalidApiKeyUid ( _ ) = > Code ::InvalidApiKeyUid ,
Self ::ApiKeyAlreadyExists ( _ ) = > Code ::ApiKeyAlreadyExists ,
2022-06-01 14:11:56 +02:00
Self ::ImmutableField ( _ ) = > Code ::ImmutableField ,
2021-11-08 18:31:27 +01:00
Self ::Internal ( _ ) = > Code ::Internal ,
}
}
}