snarkos_node_rest/helpers/
error.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkOS library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use axum::{
17    http::StatusCode,
18    response::{IntoResponse, Response},
19};
20
21/// An enum of error handlers for the REST API server.
22pub struct RestError(pub String);
23
24impl IntoResponse for RestError {
25    fn into_response(self) -> Response {
26        (StatusCode::INTERNAL_SERVER_ERROR, format!("Something went wrong: {}", self.0)).into_response()
27    }
28}
29
30impl From<anyhow::Error> for RestError {
31    fn from(err: anyhow::Error) -> Self {
32        Self(err.to_string())
33    }
34}