Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: Simplify short-circuiting logic for Option::None #1318

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions server/svix-server/src/core/operational_webhooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ impl OperationalWebhookSenderInner {
recipient_org_id: &OrganizationId,
payload: OperationalWebhook,
) -> Result<()> {
let url = match self.url.as_ref() {
Some(url) => url,
None => return Ok(()),
};
let Some(url) = &self.url else { return Ok(()) };

let op_webhook_token =
generate_management_token(&self.signing_config).map_err(Error::generic)?;
Expand Down
7 changes: 3 additions & 4 deletions server/svix-server/src/db/models/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,12 @@ impl ActiveModel {
app_id: ApplicationId,
endp_id: EndpointIdOrUid,
) -> error::Result<Option<(Self, endpointmetadata::ActiveModel)>> {
let (endp, metadata) = match Entity::secure_find_by_id_or_uid(app_id, endp_id)
let Some((endp, metadata)) = Entity::secure_find_by_id_or_uid(app_id, endp_id)
.find_also_related(endpointmetadata::Entity)
.one(db)
.await?
{
Some(models) => models,
None => return Ok(None),
else {
return Ok(None);
};

let metadata = metadata
Expand Down
21 changes: 8 additions & 13 deletions server/svix-server/src/v1/endpoints/endpoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,21 +779,16 @@ async fn send_example(
.ok_or_else(|| HttpError::not_found(None, None))?;

let example = event_type.schemas.and_then(|schema| {
schema
.example()
.and_then(|ex| serde_json::to_string(ex).ok())
let ex = schema.example()?;
serde_json::to_string(ex).ok()
});

match example {
Some(example) => example,
None => {
return Err(HttpError::bad_request(
Some("invalid_scheme".to_owned()),
Some("Unable to generate example message from event-type schema".to_owned()),
)
.into());
}
}
example.ok_or_else(|| {
HttpError::bad_request(
Some("invalid_scheme".to_owned()),
Some("Unable to generate example message from event-type schema".to_owned()),
)
})?
};

let msg_in = MessageIn {
Expand Down
11 changes: 4 additions & 7 deletions server/svix-server/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ async fn process_queue_task_inner(
return Ok(());
};

let create_message_app = match CreateMessageApp::layered_fetch(
let Some(create_message_app) = CreateMessageApp::layered_fetch(
cache,
db,
None,
Expand All @@ -789,12 +789,9 @@ async fn process_queue_task_inner(
Duration::from_secs(30),
)
.await?
{
Some(create_message_app) => create_message_app,
None => {
tracing::info!("Application doesn't exist: {}", &msg.app_id);
return Ok(());
}
else {
tracing::info!("Application doesn't exist: {}", &msg.app_id);
return Ok(());
};

let endpoints: Vec<CreateMessageEndpoint> = create_message_app
Expand Down