devlikeapro / waha

WAHA - WhatsApp HTTP API (REST API) that you can configure in a click!
https://waha.devlike.pro/
Apache License 2.0
820 stars 249 forks source link

[BUG][NOWEB] - Inconsistent API Error json #403

Open AliSot2000 opened 6 days ago

AliSot2000 commented 6 days ago

Errors Generated by the API should have documentation (ResponseScheme) as well as consistent

Causing an Exceptions like Session doesn't exist vs Endpoint doesn't exist yields HTTP Error Codes in both cases however, the returned json is different.

I'm assuming the Error Format from your api is different to that from the Router your using.

2024.6.8

{
    "version":"2024.6.8",
    "engine":"NOWEB",
    "tier":"PLUS",
    "browser":"/usr/bin/chromium"
}

To Reproduce Execute the following python code with pyhton3.12:

import aiohttp
import asyncio

async def main():

    async with aiohttp.ClientSession() as session:

        target_url = 'http://localhost:3000/api/sessions/exists'

        async with session.post(target_url, json={"name": "default", "username": "papa"}) as resp:
            json_resp = await resp.json()
            print(json_resp)

        stop_url = 'http://localhost:3000/api/sessions/stop'

        async with session.post(stop_url, json={"name": "String", "logout": True}) as resp:
            json_resp = await resp.json()
            print(json_resp)

asyncio.run(main())

Which should yield:

{'statusCode': 404, 'message': 'Cannot POST /api/sessions/exists', 'error': 'Not Found'}
{'error': {'code': 404, 'key': 'FILE_NOT_FOUND', 'message': 'File not found', 'details': 'File not found or no longer available'}}

Process finished with exit code 0

Expected behavior Consistent errors, like in FastAPI for example:

{
    "error": "Error Name" ,
    "details": "Some Message you add to inform the user what exactly went wrong", 
    "code": "number"
}

{
    "error": "File Not Found",
    "details": "The requested file didn't exist on the server."
    "code": 404
}

Engine I'm using NOWEB engine.

It would be also cool, if you could provide all possible errors in the openapi.json that you can have specific handling and not just run a general try: ... except: ... around everything and hoping you have found all exceptions in testing.