Fixed base64 error
This commit is contained in:
parent
63a21a50fd
commit
ca66a70bc1
3 changed files with 6 additions and 5 deletions
|
|
@ -11,10 +11,10 @@ pub struct ApiError {
|
|||
}
|
||||
|
||||
impl ApiError {
|
||||
pub fn new_from_string(status: StatusCode, text: String) -> Self {
|
||||
pub fn new_from_anyhow(status: StatusCode, error: anyhow::Error) -> Self {
|
||||
Self {
|
||||
status: Some(status),
|
||||
kind: ApiErrorKind::Other(anyhow::anyhow!("{}", text)),
|
||||
kind: ApiErrorKind::Other(error),
|
||||
plaintext: false,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -401,7 +401,6 @@ const ErrorDetails = (props: { details: ApiErrorDetails | null | undefined }) =>
|
|||
{details.statusText && <p><strong>{details.statusText}</strong></p>}
|
||||
<pre>{details.text}</pre>
|
||||
</>
|
||||
|
||||
}
|
||||
|
||||
const ErrorComponent = (props: { error: Error | null, remove?: () => void }) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use anyhow::Context;
|
||||
use http::StatusCode;
|
||||
use librqbit::{
|
||||
api::{
|
||||
|
|
@ -39,9 +40,10 @@ async fn torrent_create_from_base64_file(
|
|||
opts: Option<AddTorrentOptions>,
|
||||
) -> Result<ApiAddTorrentResponse, ApiError> {
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
let bytes = general_purpose::STANDARD_NO_PAD
|
||||
let bytes = general_purpose::STANDARD
|
||||
.decode(&contents)
|
||||
.map_err(|_| ApiError::new_from_string(StatusCode::BAD_REQUEST, "invalid base64".into()))?;
|
||||
.context("invalid base64")
|
||||
.map_err(|e| ApiError::new_from_anyhow(StatusCode::BAD_REQUEST, e))?;
|
||||
state
|
||||
.api
|
||||
.api_add_torrent(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue