TibiaData / tibiadata-api-go

TibiaData API written in Golang and deployed in container (version v3 and above).
https://api.tibiadata.com
MIT License
81 stars 28 forks source link

Bugfix: Return error when http code from tibia is 403 #300

Closed YoelPLG closed 9 months ago

YoelPLG commented 9 months ago

It would love to help a bit with this issue. I'm running tibiadata in my local, and did some tests to reproduce the issue. I think I know why is it failing and returning empty data. In TibiaDataHTMLDataCollector, when the request to Tibia.com is done, there are some checks on the response http code (case http.StatusForbidden:, case http.StatusFound:). But they are done inside this if clause:

if err != nil {

This only will be true in case that there is a network error or a timeout, because this refers to an error from the point of view of Resty, the library.

When Tibia.com throttles and returns 403 forbidden, the err variable is still null, so no http code checks are done.

With this changes, instead of returning a response with empty values, a proper error response is returned:

Screenshot 2023-12-12 at 13 56 24
sonarcloud[bot] commented 9 months ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

tobiasehlert commented 9 months ago

Great PR @YoelPLG, thanks! 🌟 I'll go merge #301 instead since it's covering the same fix plus tests.