Search in sources :

Example 1 with GithubConnectionException

use of wooteco.prolog.login.excetpion.GithubConnectionException in project prolog by woowacourse.

the class GithubClient method getGithubProfileFromGithub.

public GithubProfileResponse getGithubProfileFromGithub(String accessToken) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "token " + accessToken);
    HttpEntity httpEntity = new HttpEntity<>(headers);
    RestTemplate restTemplate = new RestTemplate();
    try {
        return restTemplate.exchange(profileUrl, HttpMethod.GET, httpEntity, GithubProfileResponse.class).getBody();
    } catch (HttpClientErrorException e) {
        throw new GithubConnectionException();
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) GithubProfileResponse(wooteco.prolog.login.application.dto.GithubProfileResponse) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HttpEntity(org.springframework.http.HttpEntity) RestTemplate(org.springframework.web.client.RestTemplate) GithubConnectionException(wooteco.prolog.login.excetpion.GithubConnectionException)

Aggregations

HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1 RestTemplate (org.springframework.web.client.RestTemplate)1 GithubProfileResponse (wooteco.prolog.login.application.dto.GithubProfileResponse)1 GithubConnectionException (wooteco.prolog.login.excetpion.GithubConnectionException)1