TibiaData/tibiadata-api-go

Improvement of error responses from the API

Closed this issue · 2 comments

We need to respond with proper error codes and messages.

Example scenarios:

  • 404 if the resource is not found (e.g. faulty character name)
  • 429 if the request is being throttled (tibia code is actually 403)
  • 503 if there was some upstream issue
  • and also something when tibia is having maintenance.

Section that needs to be rewritten/enhanced:

func tibiaDataRequestHandler(c *gin.Context, tibiaDataRequest TibiadataRequestStruct, requestHandler func(string) (interface{}, int), handlerName string) {
BoxContentHTML, err := TibiadataHTMLDataCollectorV3(tibiaDataRequest)
// return error (e.g. for maintenance mode)
if err != nil {
TibiaDataAPIHandleResponse(c, http.StatusBadGateway, handlerName, gin.H{"error": err.Error()})
}
jsonData, httpStatusCode := requestHandler(BoxContentHTML)
// return jsonData
TibiaDataAPIHandleResponse(c, httpStatusCode, handlerName, jsonData)
}

This should then also be added to the documentation annotation, so that docs get automatic update too.

Separate branch (feature-error-handling) created for this.

error handling implemented by #86, closing issue.