Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw WARN/INFO instead of ERROR on 404 #423

Closed
karoldrazek opened this issue Jun 4, 2018 · 4 comments
Closed

Throw WARN/INFO instead of ERROR on 404 #423

karoldrazek opened this issue Jun 4, 2018 · 4 comments
Labels
beginner A simple task perfect for beginners enhancement help wanted

Comments

@karoldrazek
Copy link

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
Copy link
Contributor

    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
Copy link
Contributor

marcinczeczko commented Jun 5, 2018

@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:

  • If status code is 2xx log on debug level
  • If status code is 3xx log as info
  • If status code is 4xx or 5xx log as warn - as it's not an application error but rather something unexpected that should warn the operator

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());

@marcinczeczko marcinczeczko added enhancement beginner A simple task perfect for beginners and removed beginner A simple task perfect for beginners labels Jun 5, 2018
@michalwronowski
Copy link
Contributor

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

@malaskowski
Copy link
Member

Fixed in #427

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginner A simple task perfect for beginners enhancement help wanted
Projects
None yet
Development

No branches or pull requests

5 participants