* [pve-devel] [RFC PATCH http-server 0/2] improve error handling on api errors
@ 2025-01-08 8:45 Dominik Csapak
2025-01-08 8:45 ` [pve-devel] [RFC PATCH http-server 1/2] add error message into http body Dominik Csapak
2025-01-08 8:45 ` [pve-devel] [RFC PATCH http-server 2/2] use HTTP_INTERNAL_SERVER_ERROR were appropriate instead of '501' Dominik Csapak
0 siblings, 2 replies; 3+ messages in thread
From: Dominik Csapak @ 2025-01-08 8:45 UTC (permalink / raw)
To: pve-devel
these two patches improve the error handling for api errors:
* put the error in the body (so we can access them in the rust client)
* use the correct error code in some places (500 instead of 501)
the second patch is not 100% necessary now IMHO, but it is more correct,
than the status quo.
Both patches modify the api response so I send it as RFC since they're
possibly breaking API changes (not sure about how we'd interpret this
though, since it's not mentioned on [0]).
0: https://pve.proxmox.com/wiki/Proxmox_VE_API#API_Stability_&_Breakage
Dominik Csapak (2):
add error message into http body
use HTTP_INTERNAL_SERVER_ERROR were appropriate instead of '501'
src/PVE/APIServer/AnyEvent.pm | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* [pve-devel] [RFC PATCH http-server 1/2] add error message into http body
2025-01-08 8:45 [pve-devel] [RFC PATCH http-server 0/2] improve error handling on api errors Dominik Csapak
@ 2025-01-08 8:45 ` Dominik Csapak
2025-01-08 8:45 ` [pve-devel] [RFC PATCH http-server 2/2] use HTTP_INTERNAL_SERVER_ERROR were appropriate instead of '501' Dominik Csapak
1 sibling, 0 replies; 3+ messages in thread
From: Dominik Csapak @ 2025-01-08 8:45 UTC (permalink / raw)
To: pve-devel
In our rust client, we can't access the http reason phrases[0], so let's
put them into the body itself if we don't specify an explicit content.
our proxmox-client code in rust already uses the body as message if
there is one [1], so we get that automatically.
0: https://github.com/hyperium/http/issues/737
1: https://git.proxmox.com/?p=proxmox.git;a=blob;f=proxmox-client/src/client.rs;h=9b078a9820405b22ca54c17ea4da4c586e0649b4;hb=refs/heads/master#l237
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/PVE/APIServer/AnyEvent.pm | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/PVE/APIServer/AnyEvent.pm b/src/PVE/APIServer/AnyEvent.pm
index 24209a1..bd76488 100644
--- a/src/PVE/APIServer/AnyEvent.pm
+++ b/src/PVE/APIServer/AnyEvent.pm
@@ -388,6 +388,7 @@ sub error {
my ($self, $reqstate, $code, $msg, $hdr, $content) = @_;
eval {
+ $content //= $msg; # write error into body by default
my $resp = HTTP::Response->new($code, $msg, $hdr, $content);
$self->response($reqstate, $resp);
};
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* [pve-devel] [RFC PATCH http-server 2/2] use HTTP_INTERNAL_SERVER_ERROR were appropriate instead of '501'
2025-01-08 8:45 [pve-devel] [RFC PATCH http-server 0/2] improve error handling on api errors Dominik Csapak
2025-01-08 8:45 ` [pve-devel] [RFC PATCH http-server 1/2] add error message into http body Dominik Csapak
@ 2025-01-08 8:45 ` Dominik Csapak
1 sibling, 0 replies; 3+ messages in thread
From: Dominik Csapak @ 2025-01-08 8:45 UTC (permalink / raw)
To: pve-devel
The http status code 501 is meant to be 'Not Implemented'[0] but that
clearly does not fit here as the default error when we encounter a
problem during handling an api request or upload.
So instead use '500' (HTTP_INTERNAL_SERVER_ERROR) which we already use
in other places where it fits.
0: https://datatracker.ietf.org/doc/html/rfc9110#name-501-not-implemented
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/PVE/APIServer/AnyEvent.pm | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/PVE/APIServer/AnyEvent.pm b/src/PVE/APIServer/AnyEvent.pm
index bd76488..3b96d2a 100644
--- a/src/PVE/APIServer/AnyEvent.pm
+++ b/src/PVE/APIServer/AnyEvent.pm
@@ -504,7 +504,7 @@ sub send_file_start {
$self->response($reqstate, $resp, $mtime, $nocomp);
};
if (my $err = $@) {
- $self->error($reqstate, 501, $err);
+ $self->error($reqstate, HTTP_INTERNAL_SERVER_ERROR, $err);
}
};
@@ -1020,7 +1020,7 @@ sub handle_api2_request {
$self->response($reqstate, $resp, undef, $nocomp, $delay);
};
if (my $err = $@) {
- $self->error($reqstate, 501, $err);
+ $self->error($reqstate, HTTP_INTERNAL_SERVER_ERROR, $err);
}
}
@@ -1214,7 +1214,7 @@ sub handle_request {
die "no such file '$path'\n";
};
if (my $err = $@) {
- $self->error($reqstate, 501, $err);
+ $self->error($reqstate, HTTP_INTERNAL_SERVER_ERROR, $err);
}
}
@@ -1304,7 +1304,7 @@ sub file_upload_multipart {
};
if (my $err = $@) {
syslog('err', $err);
- $self->error($reqstate, 501, $err);
+ $self->error($reqstate, HTTP_INTERNAL_SERVER_ERROR, $err);
}
}
@@ -1402,10 +1402,10 @@ sub process_header {
my $te = $request->header('Transfer-Encoding');
if ($te && lc($te) eq 'chunked') {
# Handle chunked transfer encoding
- $self->error($reqstate, 501, "chunked transfer encoding not supported");
+ $self->error($reqstate, HTTP_INTERNAL_SERVER_ERROR, "chunked transfer encoding not supported");
return 0;
} elsif ($te) {
- $self->error($reqstate, 501, "Unknown transfer encoding '$te'");
+ $self->error($reqstate, HTTP_INTERNAL_SERVER_ERROR, "Unknown transfer encoding '$te'");
return 0;
}
@@ -1574,7 +1574,7 @@ sub authenticate_and_handle_request {
if ($len) {
if (!($method eq 'PUT' || $method eq 'POST')) {
- $self->error($reqstate, 501, "Unexpected content for method '$method'");
+ $self->error($reqstate, HTTP_INTERNAL_SERVER_ERROR, "Unexpected content for method '$method'");
return;
}
@@ -1624,7 +1624,7 @@ sub authenticate_and_handle_request {
}
if ($len > $limit_max_post) {
- $self->error($reqstate, 501, "for data too large");
+ $self->error($reqstate, HTTP_INTERNAL_SERVER_ERROR, "for data too large");
return;
}
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-08 8:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-08 8:45 [pve-devel] [RFC PATCH http-server 0/2] improve error handling on api errors Dominik Csapak
2025-01-08 8:45 ` [pve-devel] [RFC PATCH http-server 1/2] add error message into http body Dominik Csapak
2025-01-08 8:45 ` [pve-devel] [RFC PATCH http-server 2/2] use HTTP_INTERNAL_SERVER_ERROR were appropriate instead of '501' Dominik Csapak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox