wrapperErrorhandler

package
v0.0.0-...-5bd5986 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorHandler = func(f wrapper.HandlerFunc) wrapper.HandlerFunc {
	return func(ctx context.Context, args ...interface{}) (interface{}, error) {
		res, err := f(ctx, args)
		if err != nil {
			hub := sentry.GetHubFromContext(ctx)
			logFields := []zapcore.Field{
				zap.String(loggerConstant.TYPE, loggerConstant.WORKER),
			}
			sentryContext := make(map[string]interface{})

			if ce := customError.AsCustomError(err); ce != nil {
				sentryContext[loggerConstant.CODE] = ce.Code()
				sentryContext[loggerConstant.DETAILS] = ce.Details()

				logFields = append(logFields,
					zap.Int(loggerConstant.CODE, ce.Code()),
					zap.Any(loggerConstant.DETAILS, ce.Details()),
				)
			}

			if hub != nil {
				sentryContext[loggerConstant.TYPE] = loggerConstant.WORKER
				hub.ConfigureScope(func(scope *sentry.Scope) {
					scope.SetLevel(sentry.LevelError)
					scope.SetContext("systemErr", sentryContext)
				})
				hub.CaptureException(err)
			}

			logger.Zap.Error(
				err.Error(),
				logFields...,
			)
		}

		return res, err
	}
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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