ipfs_api_prelude/response/error.rs
1// Copyright 2017 rust-ipfs-api Developers
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7//
8
9use crate::serde::Deserialize;
10use std::fmt::{self, Display, Formatter};
11
12#[derive(Debug, Deserialize)]
13#[serde(rename_all = "PascalCase")]
14pub struct ApiError {
15 pub message: String,
16 pub code: u8,
17}
18
19impl Display for ApiError {
20 fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), fmt::Error> {
21 write!(formatter, "[{}] {}", self.code, self.message)
22 }
23}