<commit_before>package auth

import (
	"net/http"
)

type Error struct {
	ID      string `json:"id"`
	Status  int    `json:"status"`
	Message string `json:"message,omitempty"`
	Cause   string `json:"cause,omitempty"`
}

func (err *Error) Error() string {
	return err.Message
}

func (err *Error) cause(cause error) *Error {
	result := &Error{}
	*result = *err
	result.Cause = cause.Error()
	return err
}

var (
	errBadAuthorizationHeader = &Error{
		ID:      "AUTH-BAD-AUTHORIZATION-HEADER",
		Status:  http.StatusUnauthorized,
		Message: "Invalid authorization header",
	}
	errUnsupportedAuthScheme = &Error{
		ID:      "AUTH-UNSUPPORTED-SCHEME",
		Status:  http.StatusUnauthorized,
		Message: "Unsupported authentication scheme",
	}
	errInvalidToken = &Error{
		ID:      "AUTH-INVALID-TOKEN",
		Status:  http.StatusUnauthorized,
		Message: "User token is invalid, please re-authenticate",
	}
	errInvalidIssuer = &Error{
		ID:      "AUTH-INVALID-ISSUER",
		Status:  http.StatusUnauthorized,
		Message: "User token was issued from another host",
	}
	errInvalidClientIP = &Error{
		ID:      "AUTH-INVALID-CLIENT-IP",
		Status:  http.StatusUnauthorized,
		Message: "User token was issued for another IP address",
	}
	errNotAdmin = &Error{
		ID:      "AUTH-NOT-ADMIN",
		Status:  http.StatusForbidden,
		Message: "You need admin privileges to make this API call",
	}
	errMalformedContent = &Error{
		ID:      "AUTH-BAD-CONTENT",
		Status:  http.StatusBadRequest,
		Message: "Malformed content",
	}
	errBadCredentials = &Error{
		ID:      "AUTH-BAD-CREDENTIALS",
		Status:  http.StatusUnauthorized,
		Message: "Invalid user credentials",
	}
	errUserNotFound = &Error{
		ID:      "AUTH-USER-NOT-FOUND",
		Status:  http.StatusUnauthorized,
		Message: "User not found",
	}
	errUnsupportedContentType = &Error{
		ID:      "AUTH-UNSUPPORTED-CONTENT-TYPE",
		Status:  http.StatusUnsupportedMediaType,
		Message: "Unrecognized data format",
	}
	errEncodeTokenFailed = &Error{
		ID:      "AUTH-ENCODE-TOKEN-FAILED",
		Status:  http.StatusUnauthorized,
		Message: "Cannot encode user token",
	}
)<commit_msg>error_code, error_messages to be https://github.com/goware/errorx compliant<commit_after>package auth

import (
	"net/http"
)

type Error struct {
	Code    string `json:"error_code,omitempty"`
	Message string `json:"error_message,omitempty"`
	Status  int    `json:"status"`
	Cause   error  `json:"cause,omitempty"`
}

func (err *Error) Error() string {
	return err.Message
}

func (err *Error) cause(cause error) *Error {
	result := &Error{}
	*result = *err
	result.Cause = cause
	return err
}

var (
	errBadAuthorizationHeader = &Error{
		Code:    "AUTH-BAD-AUTHORIZATION-HEADER",
		Status:  http.StatusUnauthorized,
		Message: "Invalid authorization header",
	}
	errUnsupportedAuthScheme = &Error{
		Code:    "AUTH-UNSUPPORTED-SCHEME",
		Status:  http.StatusUnauthorized,
		Message: "Unsupported authentication scheme",
	}
	errInvalidToken = &Error{
		Code:    "AUTH-INVALID-TOKEN",
		Status:  http.StatusUnauthorized,
		Message: "User token is invalid, please re-authenticate",
	}
	errInvalidIssuer = &Error{
		Code:    "AUTH-INVALID-ISSUER",
		Status:  http.StatusUnauthorized,
		Message: "User token was issued from another host",
	}
	errInvalidClientIP = &Error{
		Code:    "AUTH-INVALID-CLIENT-IP",
		Status:  http.StatusUnauthorized,
		Message: "User token was issued for another IP address",
	}
	errNotAdmin = &Error{
		Code:    "AUTH-NOT-ADMIN",
		Status:  http.StatusForbidden,
		Message: "You need admin privileges to make this API call",
	}
	errMalformedContent = &Error{
		Code:    "AUTH-BAD-CONTENT",
		Status:  http.StatusBadRequest,
		Message: "Malformed content",
	}
	errBadCredentials = &Error{
		Code:    "AUTH-BAD-CREDENTIALS",
		Status:  http.StatusUnauthorized,
		Message: "Invalid user credentials",
	}
	errUserNotFound = &Error{
		Code:    "AUTH-USER-NOT-FOUND",
		Status:  http.StatusUnauthorized,
		Message: "User not found",
	}
	errUnsupportedContentType = &Error{
		Code:    "AUTH-UNSUPPORTED-CONTENT-TYPE",
		Status:  http.StatusUnsupportedMediaType,
		Message: "Unrecognized data format",
	}
	errEncodeTokenFailed = &Error{
		Code:    "AUTH-ENCODE-TOKEN-FAILED",
		Status:  http.StatusUnauthorized,
		Message: "Cannot encode user token",
	}
)
{'fraction_non_alphanumeric': 0.12160262417994376, 'fraction_numerical': 0.0, 'mean_word_length': 4.088200238379023, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '697582', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1437, 'n_words': 345}