MCPcopy Index your code
hub / github.com/coder/coder / Response

Method Response

coderd/dynamicparameters/error.go:86–112  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

84}
85
86func (e *DiagnosticError) Response() (int, codersdk.Response) {
87 resp := codersdk.Response{
88 Message: e.Message,
89 Validations: nil,
90 }
91
92 // Sort the parameter names so that the order is consistent.
93 sortedNames := make([]string, 0, len(e.KeyedDiagnostics))
94 for name := range e.KeyedDiagnostics {
95 sortedNames = append(sortedNames, name)
96 }
97 slices.Sort(sortedNames)
98
99 for _, name := range sortedNames {
100 diag := e.KeyedDiagnostics[name]
101 resp.Validations = append(resp.Validations, codersdk.ValidationError{
102 Field: name,
103 Detail: DiagnosticsErrorString(diag),
104 })
105 }
106
107 if e.Diagnostics.HasErrors() {
108 resp.Detail = DiagnosticsErrorString(e.Diagnostics)
109 }
110
111 return http.StatusBadRequest, resp
112}
113
114func DiagnosticErrorString(d *hcl.Diagnostic) string {
115 return fmt.Sprintf("%s; %s", d.Summary, d.Detail)

Callers 1

Calls 1

DiagnosticsErrorStringFunction · 0.85

Tested by 1