<commit_before>package context

import (
	"fmt"
	"net/http"
	"strconv"
)

// HttpError extends the error interface to include error information for HTTP responses
type HttpError interface {
	error
	Code() int
}

// httpError is the default, internal HttpError implementation
type httpError struct {
	code    int
	message string
}

func (err *httpError) Error() string {
	return err.message
}

func (err *httpError) String() string {
	return strconv.Itoa(err.code) + ":" + err.message
}

func (err *httpError) Code() int {
	return err.code
}

// NewHttpError creates a new HttpError object.  This object implements
// go's builtin error interface.
func NewHttpError(code int, message string) HttpError {
	return &httpError{code, message}
}

// WriteJsonError writes a standard JSON error to the response
func WriteJsonError(response http.ResponseWriter, code int, message string) error {
	response.Header().Set(ContentTypeHeader, JsonContentType)
	response.Header().Set(ContentTypeOptionsHeader, NoSniff)
	response.WriteHeader(code)
	_, err := response.Write(
		[]byte(
			fmt.Sprintf(`{"message": "%s"}`, message),
		),
	)

	return err
}

// WriteError handles writing errors, possibly from panic, in a standard way.
// This method permits a variety of types for the err value.
func WriteError(response http.ResponseWriter, err interface{}) error {
	switch value := err.(type) {
	case HttpError:
		return WriteJsonError(response, value.Code(), value.Error())

	case error:
		return WriteJsonError(response, http.StatusInternalServerError, value.Error())

	case int:
		response.Header().Set(ContentTypeOptionsHeader, NoSniff)
		response.WriteHeader(value)

	default:
		response.Header().Set(ContentTypeOptionsHeader, NoSniff)
		response.WriteHeader(http.StatusInternalServerError)
	}

	return nil
}
<commit_msg>Made things a bit more concise<commit_after>package context

import (
	"fmt"
	"net/http"
	"strconv"
)

// HttpError extends the error interface to include error information for HTTP responses
type HttpError interface {
	error
	Code() int
}

// httpError is the default, internal HttpError implementation
type httpError struct {
	code    int
	message string
}

func (err *httpError) Error() string {
	return err.message
}

func (err *httpError) String() string {
	return strconv.Itoa(err.code) + ":" + err.message
}

func (err *httpError) Code() int {
	return err.code
}

// NewHttpError creates a new HttpError object.  This object implements
// go's builtin error interface.
func NewHttpError(code int, message string) HttpError {
	return &httpError{code, message}
}

// WriteJsonError writes a standard JSON error to the response
func WriteJsonError(response http.ResponseWriter, code int, message string) error {
	response.Header().Set(ContentTypeHeader, JsonContentType)
	response.Header().Set(ContentTypeOptionsHeader, NoSniff)

	response.WriteHeader(code)
	_, err := fmt.Fprintf(response, `{"message": "%s"}`, message)
	return err
}

// WriteError handles writing errors, possibly from panic, in a standard way.
// This method permits a variety of types for the err value.
func WriteError(response http.ResponseWriter, err interface{}) error {
	switch value := err.(type) {
	case HttpError:
		return WriteJsonError(response, value.Code(), value.Error())

	case error:
		return WriteJsonError(response, http.StatusInternalServerError, value.Error())

	case int:
		response.Header().Set(ContentTypeOptionsHeader, NoSniff)
		response.WriteHeader(value)

	default:
		response.Header().Set(ContentTypeOptionsHeader, NoSniff)
		response.WriteHeader(http.StatusInternalServerError)
	}

	return nil
}

{'fraction_non_alphanumeric': 0.10307564422277639, 'fraction_numerical': 0.0, 'mean_word_length': 4.9375, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '3352269', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1046, 'n_words': 336}