// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ // ┃ Copyright: (c) 2023, Mike 'PhiSyX' S. (https://github.com/PhiSyX) ┃ // ┃ SPDX-License-Identifier: MPL-2.0 ┃ // ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ // ┃ ┃ // ┃ This Source Code Form is subject to the terms of the Mozilla Public ┃ // ┃ License, v. 2.0. If a copy of the MPL was not distributed with this ┃ // ┃ file, You can obtain one at https://mozilla.org/MPL/2.0/. ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ use lexa_framework::http::response; // ----------- // // Énumération // // ----------- // #[derive(Debug)] #[derive(thiserror::Error)] pub enum ControllerError { #[error("Model error: {0}")] Model(#[from] lexa_framework::database::ModelError), } // -------------- // // Implémentation // -> Interface // -------------- // impl response::IntoResponse for ControllerError { fn into_response(self) -> response::Response { #[derive(serde::Serialize)] struct Error<'a> { status: &'a str, code: u16, message: String, } let status_code = lexa_framework::http::StatusCode::INTERNAL_SERVER_ERROR; let err = Error { status: status_code.as_str(), code: status_code.as_u16(), message: self.to_string(), }; response::Json(serde_json::json!(err)).into_response() } }