-1

Here is my code:

  public CommitResponse getOneCommitInfo(String commitHash) {
    CommitResponse commit = new CommitResponse();
    for (int i = 0; i < allCommitsList.size(); i++) {
      if (((CommitResponse) allCommitsList.get(i)).getHash().equals(commitHash)) {
        commit = (CommitResponse) allCommitsList.get(i);
        return commit;
      }
    }
    throw new HttpStatusCodeException(HttpStatus.NOT_FOUND);
  }

The exception gives Cannot instantiate the type HttpStatusCodeException Error, and I didn't find any related topics after searching for a while,

Tindona
  • 430
  • 1
  • 16
  • Which type of `HttpStatusCodeException` are you using,need to check the `import` code – flyingfox Oct 06 '22 at 13:12
  • for all we know, the HttpStatusCodeException you are using is an abstract class, and you're supposed to use a subclass – Stultuske Oct 06 '22 at 13:15
  • Assuming that you talk about `org.springframework.web.client.HttpStatusCodeException`: the class is abstract. Use one of its 2 subclasses: `HttpClientErrorException` or `HttpServerErrorException`. – f1sh Oct 06 '22 at 13:19
  • 1
    I think this is the answer you need: https://stackoverflow.com/questions/52052146/throwing-http-status-code-exception-from-handlerinterceptor – Liu Hongjie Oct 06 '22 at 13:20

1 Answers1

1

HttpStatusCodeException is abstract class so you can not instantiate it. Instead, use

throw new HttpServerErrorException();

or throw another exception.