MCPcopy Create free account
hub / github.com/apache/camel-k / maybeErrorHandler

Function maybeErrorHandler

pkg/controller/pipe/error_handler.go:33–70  ·  view source on GitHub ↗

maybeErrorHandler will return a Binding mapping a DeadLetterChannel, a Log or a None Error Handler. If the bindings has no URI, then, you can assume it's a none Error Handler.

(errHandlConf *v1.ErrorHandlerSpec, bindingContext bindings.BindingContext)

Source from the content-addressed store, hash-verified

31// maybeErrorHandler will return a Binding mapping a DeadLetterChannel, a Log or a None Error Handler.
32// If the bindings has no URI, then, you can assume it's a none Error Handler.
33func maybeErrorHandler(errHandlConf *v1.ErrorHandlerSpec, bindingContext bindings.BindingContext) (*bindings.Binding, error) {
34 if errHandlConf == nil {
35 return nil, nil
36 }
37
38 var errorHandlerBinding *bindings.Binding
39
40 errorHandlerSpec, err := parseErrorHandler(&errHandlConf.RawMessage)
41 if err != nil {
42 return nil, fmt.Errorf("could not parse error handler: %w", err)
43 }
44 // We need to get the translated URI from any referenced resource (ie, kamelets)
45 if errorHandlerSpec.Type() == v1.ErrorHandlerTypeSink {
46 errorHandlerBinding, err = bindings.Translate(
47 bindingContext,
48 bindings.EndpointContext{Type: v1.EndpointTypeErrorHandler},
49 *errorHandlerSpec.Endpoint(),
50 )
51 if err != nil {
52 return nil, fmt.Errorf("could not determine error handler URI: %w", err)
53 }
54 } else {
55 // Create a new binding otherwise in order to store error handler application properties
56 errorHandlerBinding = &bindings.Binding{
57 ApplicationProperties: make(map[string]string),
58 }
59 if errorHandlerSpec.Type() == v1.ErrorHandlerTypeLog {
60 errorHandlerBinding.URI = defaultCamelErrorHandler
61 }
62 }
63
64 err = setErrorHandlerConfiguration(errorHandlerBinding, errorHandlerSpec)
65 if err != nil {
66 return nil, fmt.Errorf("could not set integration error handler: %w", err)
67 }
68
69 return errorHandlerBinding, nil
70}
71
72func parseErrorHandler(rawMessage *v1.RawMessage) (v1.ErrorHandler, error) {
73 var properties map[v1.ErrorHandlerType]v1.RawMessage

Callers 1

CreateIntegrationForFunction · 0.85

Calls 6

TranslateFunction · 0.92
parseErrorHandlerFunction · 0.85
ErrorfMethod · 0.80
TypeMethod · 0.65
EndpointMethod · 0.65

Tested by

no test coverage detected