@Override
    public void generateError(Response response) throws IOException {
        final JsonNode errorNode;
        try {
            errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(response.getBody()).get("errors").get(0);
        } catch (JsonProcessingException ex) {
            throw new OAuth2AccessTokenErrorResponse(null, null, null, response);
        }

        OAuth2Error errorCode;
        try {
            errorCode = OAuth2Error
                    .parseFrom(extractRequiredParameter(errorNode, "errorType", response.getBody()).asText());
        } catch (IllegalArgumentException iaE) {
            //non oauth standard error code
            errorCode = null;
        }

        throw new OAuth2AccessTokenErrorResponse(errorCode, errorNode.get("message").asText(), null, response);
    }
@Test
    public void testErrorExtraction() throws IOException {

        final FitBitJsonTokenExtractor extractor = new FitBitJsonTokenExtractor();
        final OAuth2AccessTokenErrorResponse thrown = assertThrows(OAuth2AccessTokenErrorResponse.class,
                new ThrowingRunnable() {
            @Override
            public void run() throws Throwable {
                extractor.generateError(new Response(403, null, null, ERROR_JSON));
            }
        });
        assertSame(OAuth2Error.INVALID_GRANT, thrown.getError());
        assertEquals(ERROR_DESCRIPTION, thrown.getErrorDescription());
    }