Skip to content

Properly log song.link errors #24

@tooboredtocode

Description

@tooboredtocode

Properly log the errors coming from song.link, this includes modifications in the following locations:

if resp.status() != 200 {
return Err(ApiErr::Non200Response(resp.status()));
}

pub async fn map_odesli_response(
resp: Result<OdesliResponse, ApiErr>,
context: &Ctx,
inter: &Interaction,
) -> EmptyResult<OdesliResponse> {
match resp.warn_with("Failed to get the data from the api") {
Some(s) => Ok(s),
None => {
if let Some(msg_resp) = context
.interaction_client()
.create_followup(inter.token.as_str())
.content(messages::error((&inter.locale).into()))
.expect("Somehow the static string is too long, this should never happen")
.into_future()
.instrument(debug_span!("sending_error_message"))
.await
.warn_with("Failed to inform user of the error")
{
let msg = match msg_resp.model().await {
Ok(ok) => ok,
Err(_) => return Err(()),
};
let ctx = context.clone();
tokio::spawn(async move {
let _ = time::timeout(
Duration::from_secs(15),
create_termination_future(&ctx.state),
)
.await;
ctx.discord_client
.delete_message(msg.channel_id, msg.id)
.into_future()
.instrument(debug_span!("deleting_error_message"))
.await
.warn_with("Failed to delete Error Message")
});
}
Err(())
}
}
}

Note

song.link returns errors in the following format (not guaranteed, but observed thus far):

{
  "statusCode": 400,
  "code": "could_not_resolve_entity"
}

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions