Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 7 additions & 5 deletions lib/codegen/js/fetch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ payload.append("{{name}}", {{value}})
};

fetch(url, options)
.then(res => {
.then(async res => {
console.log(res.status);
return res.text()
})
.then(body => {
console.log(body);
const body = await res.text();
try {
console.log(JSON.stringify(JSON.parse(body), null, 2));
} catch {
Comment on lines +41 to +46
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an async callback inside .then(...) introduces an async/await requirement for the generated snippet (ES2017). Since the previous version used a plain promise chain, consider keeping return res.text() and moving the JSON.parse/pretty-print into the next .then(body => ...) to preserve compatibility and avoid mixing async/await with .then() here.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated snippet uses optional catch binding (catch { ... }), which is not supported in some older JS runtimes. To maximize snippet compatibility, use catch (e) { ... } even if e is unused.

Suggested change
} catch {
} catch (e) {

Copilot uses AI. Check for mistakes.
console.log(body);
}
})
.catch(err => {
console.error(`error:\${err}`);
Expand Down
6 changes: 5 additions & 1 deletion lib/codegen/python/requests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import '../codegen_utils.dart';

class PythonRequestsCodeGen {
final String kTemplateStart = """import requests
import json
{% if hasFormData %}from requests_toolbelt.multipart.encoder import MultipartEncoder
{% endif %}
url = '{{url}}'
Expand Down Expand Up @@ -67,7 +68,10 @@ payload = MultipartEncoder({
final String kStringRequestEnd = """)

print('Status Code:', response.status_code)
print('Response Body:', response.text)
try:
print(json.dumps(response.json(), indent=4))
except ValueError:
print('Response Body:', response.text)
""";

String kStringFormDataContentType = "payload.content_type";
Expand Down
Loading
Loading