Skip to content

Commit

Permalink
rename arriError to ArriError
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmossas committed Nov 12, 2024
1 parent 7cb5a23 commit 2628674
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 33 deletions.
16 changes: 8 additions & 8 deletions languages/rust/rust-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand All @@ -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 {
Expand All @@ -78,7 +78,7 @@ impl ArriRequestErrorMethods for arriError {
}
}

impl ArriModel for arriError {
impl ArriModel for ArriError {
fn new() -> Self {
Self {
code: 0,
Expand Down Expand Up @@ -192,7 +192,7 @@ impl ArriModel for arriError {
pub async fn arri_request<'a>(
opts: ArriRequestOptions<'a>,
params: Option<impl ArriModel>,
) -> Result<reqwest::Response, arriError> {
) -> Result<reqwest::Response, ArriError> {
let response: Result<reqwest::Response, reqwest::Error>;
let mut headers: HashMap<&str, String> = HashMap::new();
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -357,7 +357,7 @@ pub async fn parsed_arri_request<'a, TResponse>(
opts: ArriParsedRequestOptions<'a>,
params: Option<impl ArriModel>,
parser: fn(body: String) -> TResponse,
) -> Result<TResponse, arriError> {
) -> Result<TResponse, ArriError> {
let result = arri_request(
ArriRequestOptions {
method: opts.method,
Expand All @@ -376,15 +376,15 @@ pub async fn parsed_arri_request<'a, TResponse>(
let status = response.status().as_u16();
let body: Result<String, reqwest::Error> = 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(),
));
}
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,
Expand Down
8 changes: 4 additions & 4 deletions languages/rust/rust-client/src/sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,7 +21,7 @@ pub struct ArriParsedSseRequestOptions<'a> {

pub enum SseEvent<T> {
Message(T),
Error(arriError),
Error(ArriError),
Open,
Close,
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 {
Expand Down
9 changes: 4 additions & 5 deletions languages/rust/rust-codegen-reference/src/example_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -40,7 +39,7 @@ impl ArriClientService for ExampleClient {
}

impl ExampleClient {
pub async fn send_object(&self, params: NestedObject) -> Result<NestedObject, arriError> {
pub async fn send_object(&self, params: NestedObject) -> Result<NestedObject, ArriError> {
parsed_arri_request(
ArriParsedRequestOptions {
http_client: &self._config.http_client,
Expand Down Expand Up @@ -76,7 +75,7 @@ impl ArriClientService for ExampleClientBooksService {

impl ExampleClientBooksService {
/// Get a book
pub async fn get_book(&self, params: BookParams) -> Result<Book, arriError> {
pub async fn get_book(&self, params: BookParams) -> Result<Book, ArriError> {
parsed_arri_request(
ArriParsedRequestOptions {
http_client: &self._config.http_client,
Expand All @@ -93,7 +92,7 @@ impl ExampleClientBooksService {

/// Create a book
#[deprecated]
pub async fn create_book(&self, params: Book) -> Result<Book, arriError> {
pub async fn create_book(&self, params: Book) -> Result<Book, ArriError> {
parsed_arri_request(
ArriParsedRequestOptions {
http_client: &self._config.http_client,
Expand Down
3 changes: 1 addition & 2 deletions languages/rust/rust-codegen/src/_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export function createRustClient(
def: AppDefinition,
context: Omit<GeneratorContext, "clientVersion">,
): string {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const services = unflattenProcedures(def.procedures);
const rpcParts: string[] = [];
const subServices: { name: string; key: string }[] = [];
Expand Down Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion languages/rust/rust-codegen/src/procedures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 12 additions & 13 deletions tests/clients/rust/src/test_client.g.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -61,7 +60,7 @@ impl ArriClientService for TestClientTestsService {
}

impl TestClientTestsService {
pub async fn empty_params_get_request(&self) -> Result<DefaultPayload, arriError> {
pub async fn empty_params_get_request(&self) -> Result<DefaultPayload, ArriError> {
parsed_arri_request(
ArriParsedRequestOptions {
http_client: &self._config.http_client,
Expand All @@ -78,7 +77,7 @@ impl TestClientTestsService {
)
.await
}
pub async fn empty_params_post_request(&self) -> Result<DefaultPayload, arriError> {
pub async fn empty_params_post_request(&self) -> Result<DefaultPayload, ArriError> {
parsed_arri_request(
ArriParsedRequestOptions {
http_client: &self._config.http_client,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -168,7 +167,7 @@ impl TestClientTestsService {
pub async fn send_object(
&self,
params: ObjectWithEveryType,
) -> Result<ObjectWithEveryType, arriError> {
) -> Result<ObjectWithEveryType, ArriError> {
parsed_arri_request(
ArriParsedRequestOptions {
http_client: &self._config.http_client,
Expand All @@ -185,7 +184,7 @@ impl TestClientTestsService {
pub async fn send_object_with_nullable_fields(
&self,
params: ObjectWithEveryNullableType,
) -> Result<ObjectWithEveryNullableType, arriError> {
) -> Result<ObjectWithEveryNullableType, ArriError> {
parsed_arri_request(
ArriParsedRequestOptions {
http_client: &self._config.http_client,
Expand All @@ -205,7 +204,7 @@ impl TestClientTestsService {
pub async fn send_partial_object(
&self,
params: ObjectWithEveryOptionalType,
) -> Result<ObjectWithEveryOptionalType, arriError> {
) -> Result<ObjectWithEveryOptionalType, ArriError> {
parsed_arri_request(
ArriParsedRequestOptions {
http_client: &self._config.http_client,
Expand All @@ -222,7 +221,7 @@ impl TestClientTestsService {
pub async fn send_recursive_object(
&self,
params: RecursiveObject,
) -> Result<RecursiveObject, arriError> {
) -> Result<RecursiveObject, ArriError> {
parsed_arri_request(
ArriParsedRequestOptions {
http_client: &self._config.http_client,
Expand All @@ -242,7 +241,7 @@ impl TestClientTestsService {
pub async fn send_recursive_union(
&self,
params: RecursiveUnion,
) -> Result<RecursiveUnion, arriError> {
) -> Result<RecursiveUnion, ArriError> {
parsed_arri_request(
ArriParsedRequestOptions {
http_client: &self._config.http_client,
Expand Down

0 comments on commit 2628674

Please sign in to comment.