health.check() return not expected data
Zehir opened this issue · comments
Hello, I got some inconsistency with the return of the health.check()
method;
const client = new PocketBase(context.pocketBaseUrl)
const health = await client.health.check()
console.log(health)
For this the expected type of the health
value is:
js-sdk/src/services/HealthService.ts
Lines 4 to 8 in a169761
But with some URL I get this kind of value :
context.pocketBaseUrl | Result |
---|---|
http://127.0.0.1:8090 |
{"code": 200, "message": "API is healthy.", "data": { "canBackup": true } } |
http://existing.com |
{} |
http://not-existing.com |
Throw exception : Something went wrong while processing your request. |
https://jsonplaceholder.typicode.com/todos/1?test= |
{userId: 1, id: 1, title: 'delectus aut autem', completed: false} |
I think we need a way to verify that the target server is a PB instance and return some kind of errors if not and maybe don't throw exception ?
I'm not entirely sure that I understand what the table is and what is the desired behavior.
client.health.check()
will send a request to GET BASE_URL/api/health
and directly return the response. There is no additional handling.
If you send a /api/health
request to non-PocketBase server and it returns a 200 response, then it is up to the server and I don't think we need to check every response in the JS SDK whether the user has been connected to a PocketBase instance or some random server (and I'm not even sure how exactly this can be achieved).
The desired behavior is to make sure when using health.check()
I am sure that the server is an PocketBase server but this could be checked in the app instead of the js-sdk side
We can perform manual response data validation client-side in the SDKs, but I don't think this is the correct place where these checks should be performed.
health.check()
checks only whether a PocketBase server is up and running, it doesn't have a mechasim to verify that the server on the other side is PocketBase or not (there is no guarantee that another server will not use the same response as PocketBase).