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