Replace panic with error handling in connector handlers
The connector initiate and complete HTTP handlers used panic for operational errors (network, DB, provider failures). No recovery middleware exists on the console chi router, so these panics produced incomplete responses instead of proper HTTP 500 errors. Use the same log-and-render pattern already established in loadExistingConnector error handling. Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
@@ -116,7 +116,9 @@ func handleConnectorInitiate(
|
||||
|
||||
redirectURL, err := connectorRegistry.Initiate(r.Context(), provider, organizationID, opts, r)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot initiate connector: %w", err))
|
||||
logger.ErrorCtx(r.Context(), "cannot initiate connector", log.Error(err))
|
||||
httpserver.RenderError(w, http.StatusInternalServerError, fmt.Errorf("internal error"))
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, redirectURL, http.StatusSeeOther)
|
||||
@@ -158,4 +160,3 @@ func loadExistingConnector(
|
||||
}
|
||||
return found, err
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,9 @@ func handleConnectorComplete(
|
||||
|
||||
connection, state, err := connectorRegistry.CompleteWithState(r.Context(), provider, r)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot complete connector: %w", err))
|
||||
logger.ErrorCtx(r.Context(), "cannot complete connector", log.Error(err))
|
||||
httpserver.RenderError(w, http.StatusInternalServerError, fmt.Errorf("internal error"))
|
||||
return
|
||||
}
|
||||
|
||||
organizationID, err := gid.ParseGID(state.OrganizationID)
|
||||
@@ -184,7 +186,9 @@ func handleConnectorComplete(
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot reconnect connector: %w", err))
|
||||
logger.ErrorCtx(r.Context(), "cannot reconnect connector", log.Error(err))
|
||||
httpserver.RenderError(w, http.StatusInternalServerError, fmt.Errorf("internal error"))
|
||||
return
|
||||
}
|
||||
} else {
|
||||
cnnctr, err = svc.Connectors.Create(
|
||||
@@ -197,7 +201,9 @@ func handleConnectorComplete(
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot create connector: %w", err))
|
||||
logger.ErrorCtx(r.Context(), "cannot create connector", log.Error(err))
|
||||
httpserver.RenderError(w, http.StatusInternalServerError, fmt.Errorf("internal error"))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user