[BUG] API "404" doesn't return a 404

Posts: 5 · Views: 150
  • 24367

    So I'm working with the API, and I've noticed that if a resource is unavailable I get a 200 HTTP response code instead of the expected 404.

    For example: https://wallhaven.cc/api/v1/search/q=id:1 returns a page with the title "<title>404 - Not Found Sorry! - wallhaven.cc</title> ", but a response code of 200. I'd like to be able to catch the 404 rather than parse the response.

    Is it possible to get that changed?

    edit: I realize that the url above is missing the ?, and is invalid. But it still is responding with a "404" page with a return code of 200. edit 2: Actually it appears that the 404 page for the whole site returns a 200 code. I admit I didn't exhaustively test it, but the few tests I ran showed that.

    Last updated
  • 24385

    Hi. You do it wrong. Response is ok because you didn't knock to API. You requested page from the web. Problem is not in "?" problem in you API request. After "https://wallhaven.cc/api/v1/search" can't be slash If you allow it, you have not read the documentation carefully. Good luck

    Last updated
  • 24386

    I thought I explained that well enough in the edit, but I guess not.

    Yes my query was wrong.

    However - and this is the important part - when I enter an invalid url: for example https://wallhaven.cc/api/v1/search/fff, which is invalid, I get a response code of 200 but a page that says "404 - Not Found Sorry!"

    The problem is a 404 error should produce a 404 error code so it can be caught easily.

    I'm using this very simple code to test:

    ---- import requests

    for u in ["https://wallhaven.cc/api/v1/search/fff"]: r = requests.get(u) print(r.status_code)

    --- which prints 200 instead of the expected 404

  • 24436

    Nice. Tested to be sure and it seems to be working as expected. Thanks.

Message