fix: enable rate limit and fix error message

This commit is contained in:
2025-04-06 22:39:26 -03:00
parent f0d548aa3b
commit a64470ef75

View File

@@ -20,7 +20,7 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
errorResponse := &CuitError{Error: "Fallo exitosamente"} errorResponse := &CuitError{Error: "ocurrió un error"}
argument := r.URL.Path argument := r.URL.Path
if len(argument) == 1 { if len(argument) == 1 {
errorResponse.Error = NO_SEARCH_ARG errorResponse.Error = NO_SEARCH_ARG
@@ -29,8 +29,8 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) {
timeLeft := rate_limit.TimeLeft(r.RemoteAddr) timeLeft := rate_limit.TimeLeft(r.RemoteAddr)
if timeLeft > 0 { if timeLeft > 0 {
errorResponse.Error = fmt.Sprintf("Recurso no disponible, debe esperar %v segundos", timeLeft) errorResponse.Error = fmt.Sprintf("recurso no disponible, debe esperar %v segundos", timeLeft)
} } else {
if cuit.IsValid(argument) { if cuit.IsValid(argument) {
cRes, cErr := cache.Search(argument) cRes, cErr := cache.Search(argument)
if cErr == nil { if cErr == nil {
@@ -47,6 +47,7 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) {
} }
} }
} }
}
jsonResponse, _ := json.Marshal(errorResponse) jsonResponse, _ := json.Marshal(errorResponse)
w.Write(jsonResponse) w.Write(jsonResponse)