(self)
| 160 | |
| 161 | impl IntoResponse for ApiError { |
| 162 | fn into_response(self) -> Response { |
| 163 | use super::types::HttpError; |
| 164 | |
| 165 | match self { |
| 166 | ApiError::RateLimited { |
| 167 | message, |
| 168 | retry_after_secs, |
| 169 | } => { |
| 170 | let body = HttpError::new(message); |
| 171 | let mut resp = (StatusCode::TOO_MANY_REQUESTS, axum::Json(body)).into_response(); |
| 172 | if let Ok(val) = retry_after_secs.to_string().parse() { |
| 173 | resp.headers_mut().insert("Retry-After", val); |
| 174 | } |
| 175 | resp |
| 176 | } |
| 177 | other => { |
| 178 | let (status, message) = match other { |
| 179 | ApiError::Unauthorized(msg) => (StatusCode::UNAUTHORIZED, msg), |
| 180 | ApiError::Forbidden(msg) => (StatusCode::FORBIDDEN, msg), |
| 181 | ApiError::BadRequest(msg) => (StatusCode::BAD_REQUEST, msg), |
| 182 | ApiError::Internal(msg) => (StatusCode::INTERNAL_SERVER_ERROR, msg), |
| 183 | ApiError::RateLimited { .. } => unreachable!(), |
| 184 | ApiError::HttpStatus(code, msg) => ( |
| 185 | StatusCode::from_u16(code).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR), |
| 186 | msg, |
| 187 | ), |
| 188 | }; |
| 189 | let body = HttpError::new(message); |
| 190 | (status, axum::Json(body)).into_response() |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | /// Axum extractor that resolves and enforces HTTP auth before a handler runs. |
no test coverage detected