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
22 changes: 22 additions & 0 deletions templates/node/src/client.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,28 @@ class Client {
redirect: 'manual',
});

if (400 <= response.status) {
const responseText = await response.text();
let data: any = { message: responseText };
if (
response.headers
.get('content-type')
?.includes('application/json')
) {
try {
data = JSONbig.parse(responseText);
} catch {
// Keep the raw body as the message when the JSON is malformed
}
}
throw new {{spec.info.title | caseUcfirst}}Exception(
data?.message,
response.status,
data?.type,
responseText,
);
}
Comment on lines +649 to +669

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Redirect errors lack coverage

The new redirect error behavior has no behavioral coverage. Existing redirect tests exercise only successful 301/302 responses, while existing 4xx/5xx tests use call(). Add observable-behavior tests proving that JSON and plain-text redirect failures preserve the expected message, type, status, and response; otherwise this fix can regress undetected.

Prompt To Fix With AI
This is a comment left during a code review.
Path: templates/node/src/client.ts.twig
Line: 621-635

Comment:
**Redirect errors lack coverage**

The new redirect error behavior has no behavioral coverage. Existing redirect tests exercise only successful 301/302 responses, while existing 4xx/5xx tests use `call()`. Add observable-behavior tests proving that JSON and plain-text redirect failures preserve the expected message, type, status, and response; otherwise this fix can regress undetected.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex


if (response.status !== 301 && response.status !== 302) {
throw new {{spec.info.title | caseUcfirst}}Exception('Invalid redirect', response.status);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ abstract class Base extends TestCase
'https://localhost?code=abcdef&state=123456',
];

protected const OAUTH_EXCEPTION_RESPONSES = [
'Invalid `clientId` param: Value must be a valid string and at least 1 chars and no longer than 100 chars',
'{"message":"Invalid `clientId` param: Value must be a valid string and at least 1 chars and no longer than 100 chars","code":400}',
];

protected const DOWNLOAD_RESPONSES = [
'GET:/v1/mock/tests/general/download:passed',
];
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/Node18Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ final class Node18Test extends Base
...Base::OPTIONAL_PARAM_RESPONSES,
...Base::EXCEPTION_RESPONSES,
...Base::OAUTH_RESPONSES,
...Base::OAUTH_EXCEPTION_RESPONSES,
...Base::QUERY_HELPER_RESPONSES,
...Base::PERMISSION_HELPER_RESPONSES,
...Base::ID_HELPER_RESPONSES,
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/Node20Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ final class Node20Test extends Base
...Base::OPTIONAL_PARAM_RESPONSES,
...Base::EXCEPTION_RESPONSES,
...Base::OAUTH_RESPONSES,
...Base::OAUTH_EXCEPTION_RESPONSES,
...Base::QUERY_HELPER_RESPONSES,
...Base::PERMISSION_HELPER_RESPONSES,
...Base::ID_HELPER_RESPONSES,
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/Node26Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ final class Node26Test extends Base
...Base::OPTIONAL_PARAM_RESPONSES,
...Base::EXCEPTION_RESPONSES,
...Base::OAUTH_RESPONSES,
...Base::OAUTH_EXCEPTION_RESPONSES,
...Base::QUERY_HELPER_RESPONSES,
...Base::PERMISSION_HELPER_RESPONSES,
...Base::ID_HELPER_RESPONSES,
Expand Down
13 changes: 13 additions & 0 deletions tests/e2e/languages/node/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,19 @@ async function start() {
)
console.log(url)

try {
await general.oauth2(
'x'.repeat(101),
['test'],
'123456',
'https://localhost',
'https://localhost'
);
} catch(error) {
console.log(error.message);
console.log(error.response);
}

// Query helper tests
console.log(Query.equal("released", [true]));
console.log(Query.equal("title", ["Spiderman", "Dr. Strange"]));
Expand Down
Loading