Skip to content

Commit

Permalink
server: Simplify short-circuiting logic for Option::None (#1318)
Browse files Browse the repository at this point in the history
Using let-else in most cases, the questionmark operator elsewhere.
  • Loading branch information
svix-jplatte authored May 16, 2024
1 parent be90256 commit 97be4e9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
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

0 comments on commit 97be4e9

Please sign in to comment.