Skip to main content

bee_rest_api/types/
body.rs

1// Copyright 2020-2021 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use serde::{Deserialize, Serialize};
5
6/// A marker trait to represent the data that can be included into `SuccessBody` and `ErrorBody`.
7pub trait BodyInner {}
8
9/// Describes the response body of a successful HTTP request.
10#[derive(Clone, Debug, Serialize, Deserialize)]
11pub struct SuccessBody<T: BodyInner> {
12    pub data: T,
13}
14
15impl<T: BodyInner> SuccessBody<T> {
16    pub fn new(data: T) -> Self {
17        Self { data }
18    }
19}
20
21/// Describes the response body of a unsuccessful HTTP request.
22#[derive(Clone, Debug, Serialize)]
23pub struct ErrorBody<T: BodyInner> {
24    pub error: T,
25}
26
27impl<T: BodyInner> ErrorBody<T> {
28    pub fn new(error: T) -> Self {
29        Self { error }
30    }
31}
32
33/// Describes the default error format.
34#[derive(Clone, Debug, Serialize)]
35pub struct DefaultErrorResponse {
36    pub code: String,
37    pub message: String,
38}
39
40impl BodyInner for DefaultErrorResponse {}