@@ -5,6 +5,7 @@ package handlers
5
5
6
6
import (
7
7
"encoding/json"
8
+ "fmt"
8
9
"io/ioutil"
9
10
"log"
10
11
"net/http"
@@ -36,13 +37,14 @@ func MakeDeployHandler(functionNamespace string, factory k8s.FunctionFactory) ht
36
37
request := types.FunctionDeployment {}
37
38
err := json .Unmarshal (body , & request )
38
39
if err != nil {
39
- w .WriteHeader (http .StatusBadRequest )
40
+ wrappedErr := fmt .Errorf ("failed to unmarshal request: %s" , err .Error ())
41
+ http .Error (w , wrappedErr .Error (), http .StatusBadRequest )
40
42
return
41
43
}
42
44
43
45
if err := ValidateDeployRequest (& request ); err != nil {
44
- w . WriteHeader ( http . StatusBadRequest )
45
- w . Write ([] byte ( err .Error ()) )
46
+ wrappedErr := fmt . Errorf ( "validation failed: %s" , err . Error () )
47
+ http . Error ( w , wrappedErr .Error (), http . StatusBadRequest )
46
48
return
47
49
}
48
50
@@ -53,26 +55,27 @@ func MakeDeployHandler(functionNamespace string, factory k8s.FunctionFactory) ht
53
55
54
56
existingSecrets , err := getSecrets (factory .Client , namespace , request .Secrets )
55
57
if err != nil {
56
- w . WriteHeader ( http . StatusBadRequest )
57
- w . Write ([] byte ( err .Error ()) )
58
+ wrappedErr := fmt . Errorf ( "unable to fetch secrets: %s" , err . Error () )
59
+ http . Error ( w , wrappedErr .Error (), http . StatusBadRequest )
58
60
return
59
61
}
60
62
61
63
deploymentSpec , specErr := makeDeploymentSpec (request , existingSecrets , factory )
62
64
63
65
if specErr != nil {
64
- w .WriteHeader (http .StatusBadRequest )
65
- w .Write ([]byte (specErr .Error ()))
66
+ wrappedErr := fmt .Errorf ("failed create Deployment spec: %s" , specErr .Error ())
67
+ log .Println (wrappedErr )
68
+ http .Error (w , wrappedErr .Error (), http .StatusBadRequest )
66
69
return
67
70
}
68
71
69
72
deploy := factory .Client .AppsV1 ().Deployments (namespace )
70
73
71
74
_ , err = deploy .Create (deploymentSpec )
72
75
if err != nil {
73
- log . Println ( err )
74
- w . WriteHeader ( http . StatusInternalServerError )
75
- w . Write ([] byte ( err .Error ()) )
76
+ wrappedErr := fmt . Errorf ( "unable create Deployment: %s" , err . Error () )
77
+ log . Println ( wrappedErr )
78
+ http . Error ( w , wrappedErr .Error (), http . StatusInternalServerError )
76
79
return
77
80
}
78
81
@@ -83,9 +86,9 @@ func MakeDeployHandler(functionNamespace string, factory k8s.FunctionFactory) ht
83
86
_ , err = service .Create (serviceSpec )
84
87
85
88
if err != nil {
86
- log . Println ( err )
87
- w . WriteHeader ( http . StatusInternalServerError )
88
- w . Write ([] byte ( err .Error ()) )
89
+ wrappedErr := fmt . Errorf ( "failed create Service: %s" , err . Error () )
90
+ log . Println ( wrappedErr )
91
+ http . Error ( w , wrappedErr .Error (), http . StatusBadRequest )
89
92
return
90
93
}
91
94
0 commit comments