- Notifications
You must be signed in to change notification settings - Fork1.1k
Open
Description
This code currently operates with a control flaglisten
Lines 71 to 112 inae82770
| // The `listen` control flag determines whether to open a websocket connection to | |
| // handle the request or not. This same function is used to 'evaluate' a template | |
| // as a single invocation, or to 'listen' for a back and forth interaction with | |
| // the user to update the form as they type. | |
| // | |
| //nolint:revive // listen is a control flag | |
| func (api*API)templateVersionDynamicParameters(listenbool,initial codersdk.DynamicParametersRequest)func(rw http.ResponseWriter,r*http.Request) { | |
| returnfunc(rw http.ResponseWriter,r*http.Request) { | |
| ctx:=r.Context() | |
| templateVersion:=httpmw.TemplateVersionParam(r) | |
| renderer,err:=dynamicparameters.Prepare(ctx,api.Database,api.FileCache,templateVersion.ID, | |
| dynamicparameters.WithTemplateVersion(templateVersion), | |
| ) | |
| iferr!=nil { | |
| ifhttpapi.Is404Error(err) { | |
| httpapi.ResourceNotFound(rw) | |
| return | |
| } | |
| ifxerrors.Is(err,dynamicparameters.ErrTemplateVersionNotReady) { | |
| httpapi.Write(ctx,rw,http.StatusTooEarly, codersdk.Response{ | |
| Message:"Template version job has not finished", | |
| }) | |
| return | |
| } | |
| httpapi.Write(ctx,rw,http.StatusInternalServerError, codersdk.Response{ | |
| Message:"Internal error fetching template version data.", | |
| Detail:err.Error(), | |
| }) | |
| return | |
| } | |
| deferrenderer.Close() | |
| iflisten { | |
| api.handleParameterWebsocket(rw,r,initial,renderer) | |
| }else { | |
| api.handleParameterEvaluate(rw,r,initial,renderer) | |
| } | |
| } | |
| } |
This requires anolint and should be fixed. Additionally, http errors are not well received by websocket based FE requests. These errors should be translated to the websocket message to be properly rendered on the FE.