Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn error messages into JSON for easier parsing by the UI #985

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/http/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ impl Response {
/// Creates a response indicating initial validation.
pub fn initial_validation() -> Self {
ResponseBuilder::service_unavailable()
.content_type(ContentType::TEXT)
.body("Initial validation ongoing. Please wait.")
.content_type(ContentType::JSON)
.body("{\"error\": \"Initial validation ongoing. Please wait.\"}")
}

/// Returns a Bad Request response.
pub fn bad_request() -> Self {
ResponseBuilder::bad_request()
.content_type(ContentType::TEXT)
.body("Bad Request")
.content_type(ContentType::JSON)
.body("{\"error\": \"Bad Request\"}")
}

/// Returns a Not Modified response.
/// Returns a Not Found response.
pub fn not_found() -> Self {
ResponseBuilder::not_found()
.content_type(ContentType::TEXT)
.body("Not Found")
.content_type(ContentType::JSON)
.body("{\"error\": \"Not Found\"}")
}

/// Returns a Not Modified response.
Expand All @@ -51,8 +51,8 @@ impl Response {
/// Returns a Method Not Allowed response.
pub fn method_not_allowed() -> Self {
ResponseBuilder::method_not_allowed()
.content_type(ContentType::TEXT)
.body("Method not allowed.")
.content_type(ContentType::JSON)
.body("{\"error\": \"Method not allowed.\"}")
}

/// Returns a Moved Permanently response pointing to the given location.
Expand Down
Loading