Skip to content

Commit 37c3b08

Browse files
committed
editoast: integrate MqClientError into CoreError
Signed-off-by: hamz2a <[email protected]>
1 parent 34b84f6 commit 37c3b08

File tree

5 files changed

+33
-143
lines changed

5 files changed

+33
-143
lines changed

editoast/openapi.yaml

+20-120
Original file line numberDiff line numberDiff line change
@@ -4858,6 +4858,25 @@ components:
48584858
type: string
48594859
enum:
48604860
- editoast:coreclient:GenericCoreError
4861+
EditoastCoreErrorMqClientError:
4862+
type: object
4863+
required:
4864+
- type
4865+
- status
4866+
- message
4867+
properties:
4868+
context:
4869+
type: object
4870+
message:
4871+
type: string
4872+
status:
4873+
type: integer
4874+
enum:
4875+
- 500
4876+
type:
4877+
type: string
4878+
enum:
4879+
- editoast:coreclient:MqClientError
48614880
EditoastCoreErrorUnparsableErrorOutput:
48624881
type: object
48634882
required:
@@ -5089,6 +5108,7 @@ components:
50895108
- $ref: '#/components/schemas/EditoastCoreErrorConnectionResetByPeer'
50905109
- $ref: '#/components/schemas/EditoastCoreErrorCoreResponseFormatError'
50915110
- $ref: '#/components/schemas/EditoastCoreErrorGenericCoreError'
5111+
- $ref: '#/components/schemas/EditoastCoreErrorMqClientError'
50925112
- $ref: '#/components/schemas/EditoastCoreErrorUnparsableErrorOutput'
50935113
- $ref: '#/components/schemas/EditoastDatabaseAccessErrorDatabaseAccessError'
50945114
- $ref: '#/components/schemas/EditoastDelimitedAreaErrorInvalidLocations'
@@ -5112,12 +5132,6 @@ components:
51125132
- $ref: '#/components/schemas/EditoastListErrorsRailjsonWrongRailjsonVersionProvided'
51135133
- $ref: '#/components/schemas/EditoastMacroNodeErrorNotFound'
51145134
- $ref: '#/components/schemas/EditoastModelError'
5115-
- $ref: '#/components/schemas/EditoastMqClientErrorConnectionDoesNotExist'
5116-
- $ref: '#/components/schemas/EditoastMqClientErrorLapin'
5117-
- $ref: '#/components/schemas/EditoastMqClientErrorPoolChannelFail'
5118-
- $ref: '#/components/schemas/EditoastMqClientErrorResponseTimeout'
5119-
- $ref: '#/components/schemas/EditoastMqClientErrorSerialization'
5120-
- $ref: '#/components/schemas/EditoastMqClientErrorStatusParsing'
51215135
- $ref: '#/components/schemas/EditoastNoSuchUserErrorNoSuchUser'
51225136
- $ref: '#/components/schemas/EditoastOperationErrorEmptyId'
51235137
- $ref: '#/components/schemas/EditoastOperationErrorInvalidPatch'
@@ -5506,120 +5520,6 @@ components:
55065520
type: string
55075521
enum:
55085522
- editoast:model:ModelError
5509-
EditoastMqClientErrorConnectionDoesNotExist:
5510-
type: object
5511-
required:
5512-
- type
5513-
- status
5514-
- message
5515-
properties:
5516-
context:
5517-
type: object
5518-
message:
5519-
type: string
5520-
status:
5521-
type: integer
5522-
enum:
5523-
- 500
5524-
type:
5525-
type: string
5526-
enum:
5527-
- editoast:coreclient:ConnectionDoesNotExist
5528-
EditoastMqClientErrorLapin:
5529-
type: object
5530-
required:
5531-
- type
5532-
- status
5533-
- message
5534-
properties:
5535-
context:
5536-
type: object
5537-
message:
5538-
type: string
5539-
status:
5540-
type: integer
5541-
enum:
5542-
- 500
5543-
type:
5544-
type: string
5545-
enum:
5546-
- editoast:coreclient:Lapin
5547-
EditoastMqClientErrorPoolChannelFail:
5548-
type: object
5549-
required:
5550-
- type
5551-
- status
5552-
- message
5553-
properties:
5554-
context:
5555-
type: object
5556-
message:
5557-
type: string
5558-
status:
5559-
type: integer
5560-
enum:
5561-
- 500
5562-
type:
5563-
type: string
5564-
enum:
5565-
- editoast:coreclient:PoolChannelFail
5566-
EditoastMqClientErrorResponseTimeout:
5567-
type: object
5568-
required:
5569-
- type
5570-
- status
5571-
- message
5572-
properties:
5573-
context:
5574-
type: object
5575-
message:
5576-
type: string
5577-
status:
5578-
type: integer
5579-
enum:
5580-
- 500
5581-
type:
5582-
type: string
5583-
enum:
5584-
- editoast:coreclient:ResponseTimeout
5585-
EditoastMqClientErrorSerialization:
5586-
type: object
5587-
required:
5588-
- type
5589-
- status
5590-
- message
5591-
properties:
5592-
context:
5593-
type: object
5594-
message:
5595-
type: string
5596-
status:
5597-
type: integer
5598-
enum:
5599-
- 500
5600-
type:
5601-
type: string
5602-
enum:
5603-
- editoast:coreclient:Serialization
5604-
EditoastMqClientErrorStatusParsing:
5605-
type: object
5606-
required:
5607-
- type
5608-
- status
5609-
- message
5610-
properties:
5611-
context:
5612-
type: object
5613-
message:
5614-
type: string
5615-
status:
5616-
type: integer
5617-
enum:
5618-
- 500
5619-
type:
5620-
type: string
5621-
enum:
5622-
- editoast:coreclient:StatusParsing
56235523
EditoastNoSuchUserErrorNoSuchUser:
56245524
type: object
56255525
required:

editoast/src/core/mod.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::marker::PhantomData;
1717
use async_trait::async_trait;
1818
use axum::http::StatusCode;
1919
use editoast_derive::EditoastError;
20+
use mq_client::MqClientError;
2021
use serde::de::DeserializeOwned;
2122
use serde::Deserialize;
2223
use serde::Serialize;
@@ -48,7 +49,9 @@ pub enum CoreClient {
4849

4950
impl CoreClient {
5051
pub async fn new_mq(options: mq_client::Options) -> Result<Self> {
51-
let client = RabbitMQClient::new(options).await?;
52+
let client = RabbitMQClient::new(options)
53+
.await
54+
.map_err(CoreError::MqClientError)?;
5255

5356
Ok(Self::MessageQueue(client))
5457
}
@@ -109,7 +112,8 @@ impl CoreClient {
109112

110113
let response = client
111114
.call_with_response(infra_id.to_string(), path, &body, true, None)
112-
.await?;
115+
.await
116+
.map_err(CoreError::MqClientError)?;
113117

114118
if response.status == b"ok" {
115119
return R::from_bytes(&response.payload);
@@ -286,6 +290,10 @@ pub enum CoreError {
286290
#[editoast_error(status = 500)]
287291
BrokenPipe,
288292

293+
#[error(transparent)]
294+
#[editoast_error(status = "500")]
295+
MqClientError(MqClientError),
296+
289297
#[cfg(test)]
290298
#[error("The mocked response had no body configured - check out StubResponseBuilder::body if this is unexpected")]
291299
NoResponseContent,

editoast/src/core/mq_client.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use deadpool::managed::{Manager, Metrics, Pool, RecycleError, RecycleResult};
2-
use editoast_derive::EditoastError;
32
use futures_util::StreamExt;
43
use itertools::Itertools;
54
use lapin::{
@@ -161,26 +160,19 @@ pub struct Options {
161160
pub num_channels: usize,
162161
}
163162

164-
#[derive(Debug, Error, EditoastError)]
165-
#[editoast_error(base_id = "coreclient")]
163+
#[derive(Debug, Error)]
166164
pub enum MqClientError {
167165
#[error("AMQP error: {0}")]
168-
#[editoast_error(status = "500")]
169166
Lapin(#[from] lapin::Error),
170167
#[error("Cannot serialize request: {0}")]
171-
#[editoast_error(status = "500")]
172168
Serialization(serde_json::Error),
173169
#[error("Cannot parse response status")]
174-
#[editoast_error(status = "500")]
175170
StatusParsing,
176171
#[error("Response timeout")]
177-
#[editoast_error(status = "500")]
178172
ResponseTimeout,
179173
#[error("Connection does not exist")]
180-
#[editoast_error(status = "500")]
181174
ConnectionDoesNotExist,
182175
#[error("Fail to pool a channel")]
183-
#[editoast_error(status = "500")]
184176
PoolChannelFail,
185177
}
186178

front/public/locales/en/errors.json

+1-6
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,8 @@
4242
"ConnectionResetByPeer": "Core connection reset by peer. Should retry.",
4343
"CoreResponseFormatError": "Cannot parse Core response: {{msg}}",
4444
"GenericCoreError": "Core error {{raw_error}}",
45-
"Lapin": "Core: message queue: protocol error",
46-
"ResponseTimeout": "Core: request timeout",
47-
"Serialization": "Core: cannot serialize request",
48-
"StatusParsing": "Core: cannot parse status",
4945
"UnparsableErrorOutput": "Core returned an error in an unknown format",
50-
"ConnectionDoesNotExist": "Core: message queue: connection not established",
51-
"PoolChannelFail": "Core: message queue: channel failure"
46+
"MqClientError": "Core: MQ client error"
5247
},
5348
"DatabaseAccessError": "Database access fatal error",
5449
"delimited_area": {

front/public/locales/fr/errors.json

+1-6
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,8 @@
4242
"ConnectionResetByPeer": "Core: réinitialisation de la connexion. Nouvelle tentative.",
4343
"CoreResponseFormatError": "Core: impossible d'analyser la réponse '{{msg}}'",
4444
"GenericCoreError": "Core: erreur {{raw_error}}",
45-
"Lapin": "Core: file d'attente de messages: erreur de protocole",
46-
"ResponseTimeout": "Core: temps d'attente écoulé",
47-
"Serialization": "Core: impossible de sérialiser la requête",
48-
"StatusParsing": "Core: impossible d'obtenir le status",
4945
"UnparsableErrorOutput": "Core: a renvoyé une erreur dans un format inconnu",
50-
"ConnectionDoesNotExist": "Core: file d'attente de messages: connexion non établie",
51-
"PoolChannelFail": "Core: file d'attente de messages: erreur de pool des channels rabbitmq"
46+
"MqClientError": "Core: erreur du client MQ"
5247
},
5348
"delimited_area": {
5449
"InvalidLocations": "Certaines localisations sont invalides"

0 commit comments

Comments
 (0)