mrcore

package
v0.27.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2024 License: Apache-2.0 Imports: 2 Imported by: 40

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrHttpResponseParseData - response data is not valid.
	ErrHttpResponseParseData = mrerr.NewProto(
		"errHttpResponseParseData", mrerr.ErrorKindInternal, "response data is not valid")

	// ErrHttpFileUpload - the file with the specified key was not uploaded.
	ErrHttpFileUpload = mrerr.NewProto(
		"errHttpFileUpload", mrerr.ErrorKindUser, "the file with the specified key '{{ .key }}' was not uploaded")

	// ErrHttpMultipartFormFile - the file with the specified key cannot be processed.
	ErrHttpMultipartFormFile = mrerr.NewProto(
		"errHttpMultipartFormFile", mrerr.ErrorKindSystem, "the file with the specified key '{{ .key }}' cannot be processed")

	// ErrHttpClientUnauthorized - 401. client is unauthorized.
	ErrHttpClientUnauthorized = mrerr.NewProto(
		"errHttpClientUnauthorized", mrerr.ErrorKindUser, "401. client is unauthorized")

	// ErrHttpAccessForbidden - 403. access forbidden.
	ErrHttpAccessForbidden = mrerr.NewProto(
		"errHttpAccessForbidden", mrerr.ErrorKindUser, "403. access forbidden")

	// ErrHttpResourceNotFound - 404. resource not found.
	ErrHttpResourceNotFound = mrerr.NewProto(
		"errHttpResourceNotFound", mrerr.ErrorKindUser, "404. resource not found")

	// ErrHttpRequestParseData - 422. request body is not valid.
	ErrHttpRequestParseData = mrerr.NewProto(
		"errHttpRequestParseData", mrerr.ErrorKindInternal, "request body is not valid: {{ .reason }}'")

	// ErrHttpRequestParseParam - request param with key of type contains incorrect value.
	ErrHttpRequestParseParam = mrerr.NewProto(
		"errHttpRequestParseParam", mrerr.ErrorKindUser, "request param with key '{{ .key }}' of type '{{ .type }}' contains incorrect value '{{ .value }}'")

	// ErrHttpRequestParamEmpty - request param with key is empty.
	ErrHttpRequestParamEmpty = mrerr.NewProto(
		"errHttpRequestParamEmpty", mrerr.ErrorKindUser, "request param with key '{{ .key }}' is empty")

	// ErrHttpRequestParamMax - request param with key contains value greater than max.
	ErrHttpRequestParamMax = mrerr.NewProto(
		"errHttpRequestParamMax", mrerr.ErrorKindUser, "request param with key '{{ .key }}' contains value greater then max '{{ .max }}'")

	// ErrHttpRequestParamLenMax - request param with key has value length greater than max characters.
	ErrHttpRequestParamLenMax = mrerr.NewProto(
		"errHttpRequestParamLenMax", mrerr.ErrorKindUser, "request param with key '{{ .key }}' has value length greater then max '{{ .maxLength }}' characters")
)
View Source
var (
	// ErrUnexpectedInternal - unexpected internal error,
	// особая ошибка, в которую система заворачивает все ошибки отличные от типов AppError, ProtoAppError.
	ErrUnexpectedInternal = mrerr.NewProto(
		"errUnexpectedInternal", mrerr.ErrorKindInternal, "unexpected internal error")

	// ErrInternal - internal error,
	// обобщённая внутренняя ошибка системы которая формирует стек вызовов и посылает событие о своём создании.
	ErrInternal = mrerr.NewProto(
		mrerr.ErrorCodeInternal, mrerr.ErrorKindInternal, "internal error")

	// ErrSystem - system error,
	// обобщённая системная ошибка, которая сообщает о сетевых проблемах,
	// о работоспособности внешних ресурсов (БД, API, FileSystem).
	ErrSystem = mrerr.NewProto(
		mrerr.ErrorCodeSystem, mrerr.ErrorKindSystem, "system error")

	// ErrInternalNilPointer - unexpected nil pointer.
	ErrInternalNilPointer = mrerr.NewProto(
		"errInternalNilPointer", mrerr.ErrorKindInternal, "unexpected nil pointer")

	// ErrInternalCaughtPanic - caught panic.
	ErrInternalCaughtPanic = mrerr.NewProto(
		"errInternalCaughtPanic", mrerr.ErrorKindInternal, "{{ .source }}; panic: {{ .recover }}; callstack: {{ .callstack }}")

	// ErrInternalTypeAssertion - invalid type assertion.
	ErrInternalTypeAssertion = mrerr.NewProto(
		"errInternalTypeAssertion", mrerr.ErrorKindInternal, "invalid type '{{ .type }}' assertion (value: {{ .value }})")

	// ErrInternalInvalidType - invalid type, expected.
	ErrInternalInvalidType = mrerr.NewProto(
		"errInternalInvalidType", mrerr.ErrorKindInternal, "invalid type '{{ .currentType }}', expected: '{{ .expectedType }}'")

	// ErrInternalUnhandledDefaultCase - unhandled default case.
	ErrInternalUnhandledDefaultCase = mrerr.NewProto(
		"errInternalUnhandledDefaultCase", mrerr.ErrorKindInternal, "unhandled default case")

	// ErrInternalKeyNotFoundInSource - key is not found in source.
	ErrInternalKeyNotFoundInSource = mrerr.NewProto(
		"errInternalKeyNotFoundInSource", mrerr.ErrorKindInternal, "key '{{ .key }}' is not found in source {{ .source }}")

	// ErrInternalTimeoutPeriodHasExpired - the timeout period has expired.
	ErrInternalTimeoutPeriodHasExpired = mrerr.NewProto(
		"errInternalTimeoutPeriodHasExpired", mrerr.ErrorKindSystem, "the timeout period has expired")

	// ErrInternalFailedToOpen - failed to open object.
	ErrInternalFailedToOpen = mrerr.NewProto(
		"errInternalFailedToOpen", mrerr.ErrorKindInternal, "failed to open object")

	// ErrInternalFailedToClose - failed to close object.
	ErrInternalFailedToClose = mrerr.NewProto(
		"errInternalFailedToClose", mrerr.ErrorKindInternal, "failed to close object")

	// ErrInternalUnexpectedEOF - unexpected EOF.
	ErrInternalUnexpectedEOF = mrerr.NewProto(
		"errInternalUnexpectedEOF", mrerr.ErrorKindInternal, "unexpected EOF")

	// ErrInternalValueLenMax - value has length greater than max characters.
	ErrInternalValueLenMax = mrerr.NewProto(
		"errInternalValueLenMax", mrerr.ErrorKindInternal, "value has length '{{ .curLength }}' greater then max '{{ .maxLength }}' characters")

	// ErrInternalValueNotMatchRegexpPattern - specified value does not match regexp pattern.
	ErrInternalValueNotMatchRegexpPattern = mrerr.NewProto(
		"errInternalValueNotMatchRegexpPattern", mrerr.ErrorKindInternal, "specified value '{{ .value }}' does not match regexp pattern '{{ .pattern }}'")
)
View Source
var (
	// ErrStorageConnectionIsAlreadyCreated - connection is already created.
	ErrStorageConnectionIsAlreadyCreated = mrerr.NewProto(
		"errStorageConnectionIsAlreadyCreated", mrerr.ErrorKindInternal, "connection '{{ .name }}' is already created")

	// ErrStorageConnectionIsNotOpened - connection is not opened.
	ErrStorageConnectionIsNotOpened = mrerr.NewProto(
		"errStorageConnectionIsNotOpened", mrerr.ErrorKindInternal, "connection '{{ .name }}' is not opened")

	// ErrStorageConnectionIsBusy - connection is busy.
	ErrStorageConnectionIsBusy = mrerr.NewProto(
		"errStorageConnectionIsBusy", mrerr.ErrorKindInternal, "connection '{{ .name }}' is busy")

	// ErrStorageConnectionFailed - connection is failed.
	ErrStorageConnectionFailed = mrerr.NewProto(
		"errStorageConnectionFailed", mrerr.ErrorKindSystem, "connection '{{ .name }}' is failed")

	// ErrStorageQueryFailed - query is failed.
	ErrStorageQueryFailed = mrerr.NewProto(
		"errStorageQueryFailed", mrerr.ErrorKindInternal, "query is failed")

	// ErrStorageFetchDataFailed - fetching data is failed.
	ErrStorageFetchDataFailed = mrerr.NewProto(
		"errStorageFetchDataFailed", mrerr.ErrorKindInternal, "fetching data is failed")

	// ErrStorageNoRowFound - no row found.
	ErrStorageNoRowFound = mrerr.NewProto(
		"errStorageNoRowFound", mrerr.ErrorKindInternal, "no row found")

	// ErrStorageRowsNotAffected - rows not affected.
	ErrStorageRowsNotAffected = mrerr.NewProto(
		"errStorageRowsNotAffected", mrerr.ErrorKindInternal, "rows not affected")
)
View Source
var (
	// ErrUseCaseOperationFailed - operation failed.
	ErrUseCaseOperationFailed = mrerr.NewProto(
		"errUseCaseOperationFailed", mrerr.ErrorKindInternal, "operation failed")

	// ErrUseCaseTemporarilyUnavailable - system is temporarily unavailable.
	ErrUseCaseTemporarilyUnavailable = mrerr.NewProto(
		"errUseCaseTemporarilyUnavailable", mrerr.ErrorKindSystem, "system is temporarily unavailable")

	// ErrUseCaseIncorrectInputData - data is incorrect.
	ErrUseCaseIncorrectInputData = mrerr.NewProto(
		"errUseCaseIncorrectInputData", mrerr.ErrorKindInternal, "{{ .key }}={{ .data }} is incorrect")

	// ErrUseCaseEntityNotFound - entity not found.
	ErrUseCaseEntityNotFound = mrerr.NewProto(
		"errUseCaseEntityNotFound", mrerr.ErrorKindUser, "entity not found")

	// ErrUseCaseEntityNotAvailable - entity is not available.
	ErrUseCaseEntityNotAvailable = mrerr.NewProto(
		"errUseCaseEntityNotAvailable", mrerr.ErrorKindUser, "entity is not available")

	// ErrUseCaseEntityVersionInvalid - entity version is invalid.
	ErrUseCaseEntityVersionInvalid = mrerr.NewProto(
		"errUseCaseEntityVersionInvalid", mrerr.ErrorKindUser, "entity version is invalid")

	// ErrUseCaseSwitchStatusRejected - switching from status to status is rejected.
	ErrUseCaseSwitchStatusRejected = mrerr.NewProto(
		"errUseCaseSwitchStatusRejected", mrerr.ErrorKindUser, "switching from '{{ .statusFrom }}' to '{{ .statusTo }}' is rejected")

	// ErrUseCaseInvalidFile - file is invalid.
	ErrUseCaseInvalidFile = mrerr.NewProto(
		"errUseCaseInvalidFile", mrerr.ErrorKindUser, "file is invalid")
)

Functions

func CastToAppError added in v0.18.0

func CastToAppError(err error, defFunc func(err error) *mrerr.AppError) *mrerr.AppError

CastToAppError - приводит указанную ошибку к AppError или если это невозможно, то вызывает функцию по умолчанию, указанную в defFunc параметре, затем возвращает результат.

func PrepareError added in v0.18.0

func PrepareError(err error) error

PrepareError - приводит указанную ошибку к AppError или если это невозможно, то оборачивает её в ErrInternal ошибку, затем возвращает результат. (при этом происходит генерация ID и стека вызовов для ошибки, если в ошибке это предусмотрено). Вызываться должно как можно ближе к тому месту, где произошла непосредственно ошибка.

Types

type AnalyzedErrorType added in v0.25.0

type AnalyzedErrorType int8

AnalyzedErrorType - тип ошибки определённый обработчиком ошибок (ErrorHandler).

const (
	AnalyzedErrorTypeUndefined     AnalyzedErrorType = iota // AnalyzedErrorTypeUndefined - любая ошибка, которая не является ошибкой из списка ниже
	AnalyzedErrorTypeInternal                               // AnalyzedErrorTypeInternal - AppError with kind=ErrorKindInternal
	AnalyzedErrorTypeSystem                                 // AnalyzedErrorTypeSystem - AppError with kind=ErrorKindSystem
	AnalyzedErrorTypeUser                                   // AnalyzedErrorTypeUser - AppError with kind=ErrorKindUser
	AnalyzedErrorTypeProtoInternal                          // AnalyzedErrorTypeProtoInternal - ProtoAppError with kind=ErrorKindInternal
	AnalyzedErrorTypeProtoSystem                            // AnalyzedErrorTypeProtoSystem - ProtoAppError with kind=ErrorKindSystem
	AnalyzedErrorTypeProtoUser                              // AnalyzedErrorTypeProtoUser - ProtoAppError with kind=ErrorKindUser
)

type ErrorHandler added in v0.18.0

type ErrorHandler interface {
	Perform(ctx context.Context, err error)
	PerformWithCommit(ctx context.Context, err error, commit func(errType AnalyzedErrorType, err *mrerr.AppError))
}

ErrorHandler - обработчик ошибок.

type StorageErrorWrapper added in v0.26.0

type StorageErrorWrapper interface {
	WrapError(err error, source string) error
	WrapErrorEntity(err error, entityName string, entityData any) error
}

StorageErrorWrapper - помощник для оборачивания Storage ошибок.

type UseCaseErrorWrapper added in v0.24.0

type UseCaseErrorWrapper interface {
	IsNotFoundError(err error) bool
	WrapErrorFailed(err error, source string) error
	WrapErrorNotFoundOrFailed(err error, source string) error
	WrapErrorEntityFailed(err error, entityName string, entityData any) error
	WrapErrorEntityNotFoundOrFailed(err error, entityName string, entityData any) error
}

UseCaseErrorWrapper - помощник для оборачивания UseCase ошибок.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL