File tree 2 files changed +20
-2
lines changed
src/webserver/database/sqlpage_functions
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 14
14
- Improve error messages on invalid sqlpage function calls. The messages now contain actionable advice.
15
15
- Fix top navigation bar links color. They appeared "muted", with low contrast, since v0.33
16
16
- update to apex charts v4.5.0. This fixes a bug where tick positions in scatter plots would be incorrect.
17
+ - New function: ` sqlpage.fetch_with_meta `
18
+ - This function is similar to ` sqlpage.fetch ` , but it returns a json object with the following properties:
19
+ - ` status ` : the http status code of the response.
20
+ - ` headers ` : a json object with the response headers.
21
+ - ` body ` : the response body.
22
+ - ` error ` : an error message if the request failed.
23
+ - This is useful when interacting with complex or unreliable external APIs.
17
24
18
25
## 0.33.0 (2025-02-15)
19
26
Original file line number Diff line number Diff line change @@ -240,7 +240,13 @@ async fn fetch_with_meta(
240
240
let mut obj = encoder. serialize_map ( Some ( 3 ) ) ?;
241
241
match response_result {
242
242
Ok ( mut response) => {
243
- obj. serialize_entry ( "status" , & response. status ( ) . as_u16 ( ) ) ?;
243
+ let status = response. status ( ) ;
244
+ obj. serialize_entry ( "status" , & status. as_u16 ( ) ) ?;
245
+ let mut has_error = false ;
246
+ if status. is_server_error ( ) {
247
+ has_error = true ;
248
+ obj. serialize_entry ( "error" , & format ! ( "Server error: {status}" ) ) ?;
249
+ }
244
250
245
251
let headers = response. headers ( ) ;
246
252
@@ -286,7 +292,12 @@ async fn fetch_with_meta(
286
292
}
287
293
Err ( e) => {
288
294
log:: warn!( "Failed to read response body: {e}" ) ;
289
- obj. serialize_entry ( "error" , & format ! ( "Failed to read response body: {e}" ) ) ?;
295
+ if !has_error {
296
+ obj. serialize_entry (
297
+ "error" ,
298
+ & format ! ( "Failed to read response body: {e}" ) ,
299
+ ) ?;
300
+ }
290
301
}
291
302
}
292
303
}
You can’t perform that action at this time.
0 commit comments