fix(core): Set json content type for errors returned from commands (#9213)

This commit is contained in:
Fabian-Lars 2024-03-19 14:34:12 +01:00 committed by GitHub
parent 75f5cb4015
commit 81b853bc87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
tauri: 'patch:bug'
---
Fixed an issue where errors where returned as strings instead of objects from commands.

View File

@ -92,7 +92,7 @@ pub fn get<R: Runtime>(manager: Arc<AppManager<R>>, label: String) -> UriSchemeP
let mut response =
http::Response::new(serde_json::to_vec(&e.0).unwrap().into());
*response.status_mut() = StatusCode::BAD_REQUEST;
(response, mime::TEXT_PLAIN)
(response, mime::APPLICATION_JSON)
}
};
@ -305,7 +305,7 @@ fn handle_ipc_message<R: Runtime>(message: String, manager: &AppManager<R>, labe
mime_type = match &response {
InvokeResponse::Ok(InvokeBody::Json(_)) => mime::APPLICATION_JSON,
InvokeResponse::Ok(InvokeBody::Raw(_)) => mime::APPLICATION_OCTET_STREAM,
InvokeResponse::Err(_) => mime::TEXT_PLAIN,
InvokeResponse::Err(_) => mime::APPLICATION_JSON,
}
.essence_str()
)