Skip to content

Commit

Permalink
add new ErrorMessage type
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy committed Apr 29, 2024
1 parent 274587c commit bf75d85
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
11 changes: 11 additions & 0 deletions catalyst-gateway/bin/src/service/common/objects/error_message.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! Define `ErrorMessage` type.

use poem_openapi::Object;

/// Common error message type.
#[derive(Object)]
pub(crate) struct ErrorMessage {
/// Error message
#[oai(validator(max_length = "100"))]
pub(crate) message: String,
}
1 change: 1 addition & 0 deletions catalyst-gateway/bin/src/service/common/objects/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! This module contains common and re-usable objects.

pub(crate) mod cardano;
pub(crate) mod error_message;
pub(crate) mod legacy;
10 changes: 6 additions & 4 deletions catalyst-gateway/bin/src/service/common/responses/resp_4xx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

use poem::IntoResponse;
use poem_extensions::OneResponse;
use poem_openapi::payload::{Payload, PlainText};
use poem_openapi::payload::{Json, Payload};

use crate::service::common::objects::error_message::ErrorMessage;

#[derive(OneResponse)]
#[oai(status = 400)]
Expand All @@ -13,12 +15,12 @@ pub(crate) struct BadRequest<T: IntoResponse + Payload>(T);
#[oai(status = 400)]
/// This error means that the request was malformed.
/// It has failed to pass validation, as specified by the `OpenAPI` schema.
pub(crate) struct ApiValidationError(PlainText<String>);
pub(crate) struct ApiValidationError(Json<ErrorMessage>);

impl ApiValidationError {
/// Create new `ApiValidationError`
pub(crate) fn new(error: String) -> Self {
Self(PlainText(error))
pub(crate) fn new(message: String) -> Self {
Self(Json(ErrorMessage { message }))
}
}

Expand Down

0 comments on commit bf75d85

Please sign in to comment.