@@ -79,6 +79,17 @@ func (s *Server) extractUserK8sClient(c *gin.Context) (dynamic.Interface, error)
7979 return userClient .dynamicClient , nil
8080}
8181
82+ func respondSandboxBuildError (c * gin.Context , err error ) {
83+ switch {
84+ case errors .Is (err , api .ErrAgentRuntimeNotFound ), errors .Is (err , api .ErrCodeInterpreterNotFound ):
85+ respondError (c , http .StatusNotFound , err .Error ())
86+ case errors .Is (err , api .ErrPublicKeyMissing ):
87+ respondError (c , http .StatusServiceUnavailable , err .Error ())
88+ default :
89+ respondError (c , http .StatusInternalServerError , "internal server error" )
90+ }
91+ }
92+
8293// handleSandboxCreate handles sandbox creation given a specific kind.
8394func (s * Server ) handleSandboxCreate (c * gin.Context , kind string ) {
8495 sandboxReq := & types.CreateSandboxRequest {}
@@ -109,11 +120,7 @@ func (s *Server) handleSandboxCreate(c *gin.Context, kind string) {
109120
110121 if err != nil {
111122 klog .Errorf ("build sandbox failed %s/%s: %v" , sandboxReq .Namespace , sandboxReq .Name , err )
112- if errors .Is (err , api .ErrAgentRuntimeNotFound ) || errors .Is (err , api .ErrCodeInterpreterNotFound ) {
113- respondError (c , http .StatusNotFound , err .Error ())
114- } else {
115- respondError (c , http .StatusInternalServerError , "internal server error" )
116- }
123+ respondSandboxBuildError (c , err )
117124 return
118125 }
119126
0 commit comments