* [pve-devel] [PATCH http-server] fix #6503: return api handler errors in the json body
@ 2025-01-08 9:58 Dominik Csapak
2025-01-28 14:26 ` [pve-devel] applied: " Thomas Lamprecht
0 siblings, 1 reply; 2+ messages in thread
From: Dominik Csapak @ 2025-01-08 9:58 UTC (permalink / raw)
To: pve-devel
similar to what we do for the extjs formatter, put the error message or
status message in the 'message' property of the return object.
This way client libraries can extract the error without having to parse
the HTTP status reason phrase (which is not possible in all http
libraries, e.g. hyperium's http rust crate).
This should not be a breaking change, since it just adds a (semi) new
field to the return value.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
we could of course put the error also in the 'errors' hash with a
special key like '_api', but i opted for mirroring the 'extjs' formatter
behaviour for consistency.
src/PVE/APIServer/Formatter/Standard.pm | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/PVE/APIServer/Formatter/Standard.pm b/src/PVE/APIServer/Formatter/Standard.pm
index 5211473..eca928d 100644
--- a/src/PVE/APIServer/Formatter/Standard.pm
+++ b/src/PVE/APIServer/Formatter/Standard.pm
@@ -33,6 +33,10 @@ sub prepare_response_data {
$res->{status} = 200;
}
$new->{success} = $success;
+ } elsif ($format eq 'json') {
+ if (HTTP::Status::is_error($res->{status})) {
+ $new->{message} = "$res->{message}" || status_message($res->{status});
+ }
}
if ($success && $res->{total}) {
--
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] 2+ messages in thread
* [pve-devel] applied: [PATCH http-server] fix #6503: return api handler errors in the json body
2025-01-08 9:58 [pve-devel] [PATCH http-server] fix #6503: return api handler errors in the json body Dominik Csapak
@ 2025-01-28 14:26 ` Thomas Lamprecht
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2025-01-28 14:26 UTC (permalink / raw)
To: Proxmox VE development discussion, Dominik Csapak
Am 08.01.25 um 10:58 schrieb Dominik Csapak:
> similar to what we do for the extjs formatter, put the error message or
> status message in the 'message' property of the return object.
>
> This way client libraries can extract the error without having to parse
> the HTTP status reason phrase (which is not possible in all http
> libraries, e.g. hyperium's http rust crate).
>
> This should not be a breaking change, since it just adds a (semi) new
> field to the return value.
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> we could of course put the error also in the 'errors' hash with a
> special key like '_api', but i opted for mirroring the 'extjs' formatter
> behaviour for consistency.
>
> src/PVE/APIServer/Formatter/Standard.pm | 4 ++++
> 1 file changed, 4 insertions(+)
>
>
applied, thanks!
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-01-28 14:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-08 9:58 [pve-devel] [PATCH http-server] fix #6503: return api handler errors in the json body Dominik Csapak
2025-01-28 14:26 ` [pve-devel] applied: " Thomas Lamprecht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox