Skip to content

Commit e81ddc1

Browse files
committed
fix(cts): add tests for HTML error
1 parent ff95467 commit e81ddc1

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

scripts/cts/testServer/timeout.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ function addRoutes(app: express.Express): void {
9797

9898
// no response, just hang
9999
});
100+
101+
app.get('/1/html-error', (req, res) => {
102+
res.setHeader('Content-Type', 'text/html');
103+
res.status(429).send('<html><body>429 Too Many Requests</body></html>');
104+
});
100105
}
101106

102107
export function timeoutServer(): Promise<Server> {

tests/CTS/client/ingestion/api.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"testName": "can handle HTML error",
4+
"autoCreateClient": false,
5+
"steps": [
6+
{
7+
"type": "createClient",
8+
"parameters": {
9+
"appId": "test-app-id",
10+
"apiKey": "test-api-key",
11+
"region": "us",
12+
"customHosts": [
13+
{
14+
"port": 6676
15+
}
16+
]
17+
}
18+
},
19+
{
20+
"type": "method",
21+
"method": "customGet",
22+
"parameters": {
23+
"path": "1/html-error"
24+
},
25+
"expected": {
26+
"error": {
27+
"csharp": "<html><body>429 too many requests</body></html>",
28+
"go": "API error [429] Too Many Requests",
29+
"java": "Status Code: 429 - <html><body>429 Too Many Requests</body></html>",
30+
"javascript": "<html><body>429 Too Many Requests</body></html>",
31+
"kotlin": "Client request(GET http://%localhost%:6676/1/html-error) invalid: 429 Too Many Requests. Text: \"<html><body>429 Too Many Requests</body></html>\"",
32+
"php": "json_decode error: Syntax error",
33+
"python": "Too Many Requests",
34+
"ruby": "unexpected token at '<html><body>429 Too Many Requests</body></html>'",
35+
"scala": "<html><body>429 Too Many Requests</body></html>",
36+
"swift": "HTTP error: Status code: 429 Message: No message"
37+
}
38+
}
39+
}
40+
]
41+
}
42+
]

tests/output/scala/src/test/scala/algoliasearch/package.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ package object algoliasearch {
1010

1111
def assertError(message: String)(call: => Unit)(implicit ec: ExecutionContextExecutor): Unit = {
1212
val error = intercept[Exception](call)
13-
assert(error.getMessage == message)
13+
assert(
14+
error.getMessage == message,
15+
s"Error message does not match, expected: $message, got: ${error.getMessage}"
16+
)
1417
}
1518

1619
@targetName("assertErrorFuture")

0 commit comments

Comments
 (0)