Knotx / knotx

Knot.x is a highly-efficient and scalable integration framework designed to build backend APIs
https://knotx.io
Apache License 2.0
126 stars 26 forks source link

Throw WARN/INFO instead of ERROR on 404 #423

Closed karoldrazek closed 6 years ago

karoldrazek commented 6 years ago

Please kindly consider throwing WARN or INFO rather than ERROR when there's 404 being thrown from repository.

Relevant code part: https://github.com/Cognifide/knotx/blob/master/knotx-core/src/main/java/io/knotx/repository/http/HttpRepositoryConnectorProxyImpl.java#L151

toniedzwiedz commented 6 years ago
    if (httpResponse.statusCode() >= 300 && httpResponse.statusCode() < 400) { //redirect responses
      LOGGER.info("Repository 3xx response: {}, Headers[{}]", httpResponse.statusCode(),
          DataObjectsUtil.toString(httpResponse.headers()));
    } else if (httpResponse.statusCode() != 200) {
      LOGGER.error("Repository error response: {}, Headers[{}]", httpResponse.statusCode(),
          DataObjectsUtil.toString(httpResponse.headers()));
    }

I'm not sure I understand this correctly but doesn't this effectively treat a number of 2xx family status codes as errors?

As for @karoldrazek 's suggestion, perhaps the log level could be different for 4xx codes (warn/info) and for 5xx codes (error), the rationale being that the 400s can usually be fixed by the client by changing the request accordingly, whereas the 500s are server-side errors beyond the client's control.

marcinczeczko commented 6 years ago

@toniedzwiedz check the condition, the response is logged as error if status code is different than 200. Anyway, this method is a great candidate for someone who'd like to contribute first time. In my opinion that if statement should log the repository responses in a following way:

And small tip. Instead of checking ranges of status codes, you can use a HttpStatusClass enum that simplifies response code checking, e.g., in order to test if the 500 =< code < 600 use:

import io.netty.handler.codec.http.HttpStatusClass;

HttpStatusClass.SERVER_ERROR.contains(httpResponse.statusCode());
michalwronowski commented 6 years ago

Logging 5xx on error level as @toniedzwiedz suggested seems very reasonable.

malaskowski commented 6 years ago

Fixed in #427