From 26286741f5b6498fbc54b2503bc6763bd9ca0f42 Mon Sep 17 00:00:00 2001 From: Joshua Sosso Date: Tue, 12 Nov 2024 14:53:01 -0600 Subject: [PATCH] rename arriError to ArriError --- languages/rust/rust-client/src/lib.rs | 16 ++++++------ languages/rust/rust-client/src/sse.rs | 8 +++--- .../src/example_client.rs | 9 +++---- languages/rust/rust-codegen/src/_index.ts | 3 +-- languages/rust/rust-codegen/src/procedures.ts | 2 +- tests/clients/rust/src/test_client.g.rs | 25 +++++++++---------- 6 files changed, 30 insertions(+), 33 deletions(-) diff --git a/languages/rust/rust-client/src/lib.rs b/languages/rust/rust-client/src/lib.rs index 594b69f1..5f26a05b 100644 --- a/languages/rust/rust-client/src/lib.rs +++ b/languages/rust/rust-client/src/lib.rs @@ -54,7 +54,7 @@ pub struct ArriParsedRequestOptions<'a> { } #[derive(Debug)] -pub struct arriError { +pub struct ArriError { pub code: u16, pub message: String, pub stack: Option, @@ -65,7 +65,7 @@ trait ArriRequestErrorMethods { fn from_response_data(status: u16, body: String) -> Self; } -impl ArriRequestErrorMethods for arriError { +impl ArriRequestErrorMethods for ArriError { fn from_response_data(status: u16, body: String) -> Self { let mut err = Self::from_json_string(body.to_owned()); if err.code == 0 { @@ -78,7 +78,7 @@ impl ArriRequestErrorMethods for arriError { } } -impl ArriModel for arriError { +impl ArriModel for ArriError { fn new() -> Self { Self { code: 0, @@ -192,7 +192,7 @@ impl ArriModel for arriError { pub async fn arri_request<'a>( opts: ArriRequestOptions<'a>, params: Option, -) -> Result { +) -> Result { let response: Result; let mut headers: HashMap<&str, String> = HashMap::new(); { @@ -302,7 +302,7 @@ pub async fn arri_request<'a>( match response { Ok(res) => return Ok(res), Err(err) => { - return Err(arriError { + return Err(ArriError { code: err.status().unwrap_or(StatusCode::default()).as_u16(), message: format!("Error requesting \"{}\"", opts.url), stack: None, @@ -357,7 +357,7 @@ pub async fn parsed_arri_request<'a, TResponse>( opts: ArriParsedRequestOptions<'a>, params: Option, parser: fn(body: String) -> TResponse, -) -> Result { +) -> Result { let result = arri_request( ArriRequestOptions { method: opts.method, @@ -376,7 +376,7 @@ pub async fn parsed_arri_request<'a, TResponse>( let status = response.status().as_u16(); let body: Result = response.text().await; if status >= 300 || status < 200 { - return Err(arriError::from_response_data( + return Err(ArriError::from_response_data( status, body.unwrap_or_default(), )); @@ -384,7 +384,7 @@ pub async fn parsed_arri_request<'a, TResponse>( match body { Ok(text) => return Ok(parser(text)), Err(err) => { - return Err(arriError { + return Err(ArriError { code: status, message: "Expected server to return plaintext".to_string(), stack: None, diff --git a/languages/rust/rust-client/src/sse.rs b/languages/rust/rust-client/src/sse.rs index 9fcfbfdc..47021e49 100644 --- a/languages/rust/rust-client/src/sse.rs +++ b/languages/rust/rust-client/src/sse.rs @@ -5,7 +5,7 @@ use std::{ time::{Duration, Instant}, }; -use crate::{ArriModel, ArriRequestErrorMethods, arriError}; +use crate::{ArriError, ArriModel, ArriRequestErrorMethods}; pub struct ArriParsedSseRequestOptions<'a> { pub client: &'a reqwest::Client, @@ -21,7 +21,7 @@ pub struct ArriParsedSseRequestOptions<'a> { pub enum SseEvent { Message(T), - Error(arriError), + Error(ArriError), Open, Close, } @@ -204,7 +204,7 @@ impl<'a> EventSource<'a> { } if !response.is_ok() { - on_event(SseEvent::Error(arriError::new()), &mut controller); + on_event(SseEvent::Error(ArriError::new()), &mut controller); if controller.is_aborted { return SseAction::Abort; } @@ -219,7 +219,7 @@ impl<'a> EventSource<'a> { if status < 200 || status >= 300 { let body = ok_response.text().await.unwrap_or_default(); on_event( - SseEvent::Error(arriError::from_response_data(status, body)), + SseEvent::Error(ArriError::from_response_data(status, body)), &mut controller, ); if controller.is_aborted { diff --git a/languages/rust/rust-codegen-reference/src/example_client.rs b/languages/rust/rust-codegen-reference/src/example_client.rs index 2bbf03bc..463ea730 100644 --- a/languages/rust/rust-codegen-reference/src/example_client.rs +++ b/languages/rust/rust-codegen-reference/src/example_client.rs @@ -6,14 +6,13 @@ deprecated )] use arri_client::{ - arriError, chrono::{DateTime, FixedOffset}, parsed_arri_request, reqwest::{self, Request}, serde_json::{self, Map}, sse::{parsed_arri_sse_request, ArriParsedSseRequestOptions, SseController, SseEvent}, utils::{serialize_date_time, serialize_string}, - ArriClientConfig, ArriClientService, ArriEnum, ArriModel, ArriParsedRequestOptions, + ArriClientConfig, ArriClientService, ArriEnum, ArriError, ArriModel, ArriParsedRequestOptions, EmptyArriModel, InternalArriClientConfig, }; use std::collections::{BTreeMap, HashMap}; @@ -40,7 +39,7 @@ impl ArriClientService for ExampleClient { } impl ExampleClient { - pub async fn send_object(&self, params: NestedObject) -> Result { + pub async fn send_object(&self, params: NestedObject) -> Result { parsed_arri_request( ArriParsedRequestOptions { http_client: &self._config.http_client, @@ -76,7 +75,7 @@ impl ArriClientService for ExampleClientBooksService { impl ExampleClientBooksService { /// Get a book - pub async fn get_book(&self, params: BookParams) -> Result { + pub async fn get_book(&self, params: BookParams) -> Result { parsed_arri_request( ArriParsedRequestOptions { http_client: &self._config.http_client, @@ -93,7 +92,7 @@ impl ExampleClientBooksService { /// Create a book #[deprecated] - pub async fn create_book(&self, params: Book) -> Result { + pub async fn create_book(&self, params: Book) -> Result { parsed_arri_request( ArriParsedRequestOptions { http_client: &self._config.http_client, diff --git a/languages/rust/rust-codegen/src/_index.ts b/languages/rust/rust-codegen/src/_index.ts index 9b608f43..8b95d901 100644 --- a/languages/rust/rust-codegen/src/_index.ts +++ b/languages/rust/rust-codegen/src/_index.ts @@ -92,7 +92,6 @@ export function createRustClient( def: AppDefinition, context: Omit, ): string { - // eslint-disable-next-line @typescript-eslint/no-unused-vars const services = unflattenProcedures(def.procedures); const rpcParts: string[] = []; const subServices: { name: string; key: string }[] = []; @@ -172,7 +171,7 @@ use arri_client::{ sse::{parsed_arri_sse_request, ArriParsedSseRequestOptions, SseController, SseEvent}, utils::{serialize_date_time, serialize_string}, ArriClientConfig, ArriClientService, ArriEnum, ArriModel, ArriParsedRequestOptions, - arriError, EmptyArriModel, InternalArriClientConfig, + ArriError, EmptyArriModel, InternalArriClientConfig, }; use std::collections::{BTreeMap, HashMap}; diff --git a/languages/rust/rust-codegen/src/procedures.ts b/languages/rust/rust-codegen/src/procedures.ts index 21407517..6415aab2 100644 --- a/languages/rust/rust-codegen/src/procedures.ts +++ b/languages/rust/rust-codegen/src/procedures.ts @@ -78,7 +78,7 @@ export function rustHttpRpcFromSchema( return `${leading}pub async fn ${functionName}( &self, ${params ? `params: ${context.typeNamePrefix}${params},` : ""} - ) -> Result<${context.typeNamePrefix}${response ?? "()"}, arriError> { + ) -> Result<${context.typeNamePrefix}${response ?? "()"}, ArriError> { parsed_arri_request( ArriParsedRequestOptions { http_client: &self._config.http_client, diff --git a/tests/clients/rust/src/test_client.g.rs b/tests/clients/rust/src/test_client.g.rs index 51d880b8..0289dd6e 100644 --- a/tests/clients/rust/src/test_client.g.rs +++ b/tests/clients/rust/src/test_client.g.rs @@ -6,14 +6,13 @@ deprecated )] use arri_client::{ - arriError, chrono::{DateTime, FixedOffset}, parsed_arri_request, reqwest::{self, Request}, serde_json::{self, Map}, sse::{parsed_arri_sse_request, ArriParsedSseRequestOptions, SseController, SseEvent}, utils::{serialize_date_time, serialize_string}, - ArriClientConfig, ArriClientService, ArriEnum, ArriModel, ArriParsedRequestOptions, + ArriClientConfig, ArriClientService, ArriEnum, ArriError, ArriModel, ArriParsedRequestOptions, EmptyArriModel, InternalArriClientConfig, }; use std::collections::{BTreeMap, HashMap}; @@ -61,7 +60,7 @@ impl ArriClientService for TestClientTestsService { } impl TestClientTestsService { - pub async fn empty_params_get_request(&self) -> Result { + pub async fn empty_params_get_request(&self) -> Result { parsed_arri_request( ArriParsedRequestOptions { http_client: &self._config.http_client, @@ -78,7 +77,7 @@ impl TestClientTestsService { ) .await } - pub async fn empty_params_post_request(&self) -> Result { + pub async fn empty_params_post_request(&self) -> Result { parsed_arri_request( ArriParsedRequestOptions { http_client: &self._config.http_client, @@ -98,7 +97,7 @@ impl TestClientTestsService { pub async fn empty_response_get_request( &self, params: DefaultPayload, - ) -> Result<(), arriError> { + ) -> Result<(), ArriError> { parsed_arri_request( ArriParsedRequestOptions { http_client: &self._config.http_client, @@ -118,7 +117,7 @@ impl TestClientTestsService { pub async fn empty_response_post_request( &self, params: DefaultPayload, - ) -> Result<(), arriError> { + ) -> Result<(), ArriError> { parsed_arri_request( ArriParsedRequestOptions { http_client: &self._config.http_client, @@ -137,7 +136,7 @@ impl TestClientTestsService { } /// If the target language supports it. Generated code should mark this procedure as deprecated. #[deprecated] - pub async fn deprecated_rpc(&self, params: DeprecatedRpcParams) -> Result<(), arriError> { + pub async fn deprecated_rpc(&self, params: DeprecatedRpcParams) -> Result<(), ArriError> { parsed_arri_request( ArriParsedRequestOptions { http_client: &self._config.http_client, @@ -151,7 +150,7 @@ impl TestClientTestsService { ) .await } - pub async fn send_error(&self, params: SendErrorParams) -> Result<(), arriError> { + pub async fn send_error(&self, params: SendErrorParams) -> Result<(), ArriError> { parsed_arri_request( ArriParsedRequestOptions { http_client: &self._config.http_client, @@ -168,7 +167,7 @@ impl TestClientTestsService { pub async fn send_object( &self, params: ObjectWithEveryType, - ) -> Result { + ) -> Result { parsed_arri_request( ArriParsedRequestOptions { http_client: &self._config.http_client, @@ -185,7 +184,7 @@ impl TestClientTestsService { pub async fn send_object_with_nullable_fields( &self, params: ObjectWithEveryNullableType, - ) -> Result { + ) -> Result { parsed_arri_request( ArriParsedRequestOptions { http_client: &self._config.http_client, @@ -205,7 +204,7 @@ impl TestClientTestsService { pub async fn send_partial_object( &self, params: ObjectWithEveryOptionalType, - ) -> Result { + ) -> Result { parsed_arri_request( ArriParsedRequestOptions { http_client: &self._config.http_client, @@ -222,7 +221,7 @@ impl TestClientTestsService { pub async fn send_recursive_object( &self, params: RecursiveObject, - ) -> Result { + ) -> Result { parsed_arri_request( ArriParsedRequestOptions { http_client: &self._config.http_client, @@ -242,7 +241,7 @@ impl TestClientTestsService { pub async fn send_recursive_union( &self, params: RecursiveUnion, - ) -> Result { + ) -> Result { parsed_arri_request( ArriParsedRequestOptions { http_client: &self._config.http_client,