<commit_before>package api

import (
	"crypto/tls"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
)

type AuthorizedRequest struct {
	*http.Request
}

type errorResponse struct {
	Code        int
	Description string
}

func newClient() *http.Client {
	tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
	return &http.Client{Transport: tr}
}

func NewAuthorizedRequest(method, path, accessToken string, body io.Reader) (*AuthorizedRequest, error) {
	request, err := http.NewRequest(method, path, body)
	if err != nil {
		return nil, err
	}
	request.Header.Set("Authorization", accessToken)
	request.Header.Set("accept", "application/json")

	return &AuthorizedRequest{request}, err
}

func PerformRequest(request *AuthorizedRequest) (err error) {
	client := newClient()

	rawResponse, err := client.Do(request.Request)

	if err != nil {
		err = errors.New(fmt.Sprintf("Error performing request: %s", err.Error()))
		return
	}

	if rawResponse.StatusCode > 299 {
		errorResponse := getErrorResponse(rawResponse)
		message := fmt.Sprintf("Server error, status code: %d, message: %s", rawResponse.StatusCode, errorResponse.Description)
		err = errors.New(message)
	}
	return
}

func PerformRequestForBody(request *AuthorizedRequest, response interface{}) (err error) {
	client := newClient()

	rawResponse, err := client.Do(request.Request)

	if err != nil {
		err = errors.New(fmt.Sprintf("Error performing request: %s", err.Error()))
		return
	}

	if rawResponse.StatusCode > 299 {
		errorResponse := getErrorResponse(rawResponse)
		message := fmt.Sprintf("Server error, status code: %d, message: %s", rawResponse.StatusCode, errorResponse.Description)
		err = errors.New(message)
		return
	}

	jsonBytes, err := ioutil.ReadAll(rawResponse.Body)
	rawResponse.Body.Close()

	if err != nil {
		err = errors.New(fmt.Sprintf("Could not read response body: %s", err.Error()))
		return
	}
<commit_msg>Include error code in output<commit_after>package api

import (
	"crypto/tls"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
)

type AuthorizedRequest struct {
	*http.Request
}

type errorResponse struct {
	Code        int
	Description string
}

func newClient() *http.Client {
	tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
	return &http.Client{Transport: tr}
}

func NewAuthorizedRequest(method, path, accessToken string, body io.Reader) (*AuthorizedRequest, error) {
	request, err := http.NewRequest(method, path, body)
	if err != nil {
		return nil, err
	}
	request.Header.Set("Authorization", accessToken)
	request.Header.Set("accept", "application/json")

	return &AuthorizedRequest{request}, err
}

func PerformRequest(request *AuthorizedRequest) (err error) {
	client := newClient()

	rawResponse, err := client.Do(request.Request)

	if err != nil {
		err = errors.New(fmt.Sprintf("Error performing request: %s", err.Error()))
		return
	}

	if rawResponse.StatusCode > 299 {
		errorResponse := getErrorResponse(rawResponse)
		message := fmt.Sprintf("Server error, status code: %d, error code: %d, message: %s", rawResponse.StatusCode, errorResponse.Code, errorResponse.Description)
		err = errors.New(message)
	}
	return
}

func PerformRequestForBody(request *AuthorizedRequest, response interface{}) (err error) {
	client := newClient()

	rawResponse, err := client.Do(request.Request)

	if err != nil {
		err = errors.New(fmt.Sprintf("Error performing request: %s", err.Error()))
		return
	}

	if rawResponse.StatusCode > 299 {
		errorResponse := getErrorResponse(rawResponse)
		message := fmt.Sprintf("Server error, status code: %d, error code: %d, message: %s", rawResponse.StatusCode, errorResponse.Code, errorResponse.Description)
		err = errors.New(message)
		return
	}

	jsonBytes, err := ioutil.ReadAll(rawResponse.Body)
	rawResponse.Body.Close()

	if err != nil {
		err = errors.New(fmt.Sprintf("Could not read response body: %s", err.Error()))
		return
	}

{'fraction_non_alphanumeric': 0.1348427672955975, 'fraction_numerical': 0.0030188679245283017, 'mean_word_length': 4.838472834067548, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4079482', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1276, 'n_words': 318}