@@ -89,33 +89,17 @@ impl From<anyhow::Error> for ApiError {
8989impl From < crate :: secrets:: SecretError > for ApiError {
9090 fn from ( e : crate :: secrets:: SecretError ) -> Self {
9191 use crate :: secrets:: SecretError ;
92- match e {
93- SecretError :: NotFound ( name) => {
94- ApiError :: not_found ( format ! ( "Secret '{}' not found" , name) )
92+ let constructor = match & e {
93+ SecretError :: NotFound ( _) => ApiError :: not_found,
94+ SecretError :: AlreadyExists ( _) | SecretError :: CreationInProgress ( _) => {
95+ ApiError :: conflict
9596 }
96- SecretError :: AlreadyExists ( name) => {
97- ApiError :: conflict ( format ! ( "Secret '{}' already exists" , name) )
97+ SecretError :: NotConfigured => ApiError :: service_unavailable,
98+ SecretError :: InvalidName ( _) => ApiError :: bad_request,
99+ SecretError :: Backend ( _) | SecretError :: InvalidUtf8 | SecretError :: Database ( _) => {
100+ ApiError :: internal_error
98101 }
99- SecretError :: CreationInProgress ( name) => {
100- ApiError :: conflict ( format ! (
101- "Secret '{}' is being created by another process; delete it first if you want to retry" ,
102- name
103- ) )
104- }
105- SecretError :: NotConfigured => {
106- ApiError :: service_unavailable ( "Secret manager not configured" )
107- }
108- SecretError :: InvalidName ( name) => ApiError :: bad_request ( format ! (
109- "Invalid secret name '{}': must be 1-128 characters, alphanumeric with _ and - only" ,
110- name
111- ) ) ,
112- SecretError :: Backend ( msg) => {
113- ApiError :: internal_error ( format ! ( "Backend error: {}" , msg) )
114- }
115- SecretError :: InvalidUtf8 => ApiError :: internal_error ( "Invalid UTF-8 in secret" ) ,
116- SecretError :: Database ( msg) => {
117- ApiError :: internal_error ( format ! ( "Database error: {}" , msg) )
118- }
119- }
102+ } ;
103+ constructor ( e. to_string ( ) )
120104 }
121105}
0 commit comments