Skip to content

Commit

Permalink
응답코드가 200이 아닐때 상태코드를 담아 반환하는 예외추가
Browse files Browse the repository at this point in the history
  • Loading branch information
dolong2 committed Jan 25, 2023
1 parent 399b022 commit e12a541
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/gauth/GAuth.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gauth;

import com.fasterxml.jackson.databind.ObjectMapper;
import gauth.exception.GAuthException;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
Expand Down Expand Up @@ -124,7 +125,7 @@ private static Map<String, String> sendPost(Map<String, String> body, String tok
CloseableHttpClient client = HttpClientBuilder.create().build();
CloseableHttpResponse response = client.execute(request);
if(response.getStatusLine().getStatusCode()!=200)
throw new RuntimeException();
throw new GAuthException(response.getStatusLine().getStatusCode());
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String responseBody = bufferedReader.readLine();
bufferedReader.close();
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/gauth/exception/GAuthException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package gauth.exception;

public class GAuthException extends RuntimeException{
private final Integer code;

public GAuthException(Integer code) {
super(code.toString());
this.code = code;
}

public Integer getCode() {
return code;
}
}

0 comments on commit e12a541

Please sign in to comment.