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

Function writeAgentChatError

coderd/workspaceagents.go:2966–3014  ·  view source on GitHub ↗

writeAgentChatError translates resolveAgentChat errors to HTTP responses.

(
	ctx context.Context,
	rw http.ResponseWriter,
	err error,
)

Source from the content-addressed store, hash-verified

2964// writeAgentChatError translates resolveAgentChat errors to HTTP
2965// responses.
2966func writeAgentChatError(
2967 ctx context.Context,
2968 rw http.ResponseWriter,
2969 err error,
2970) {
2971 if errors.Is(err, errNoActiveChats) {
2972 httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
2973 Message: "No active chats found for this agent.",
2974 })
2975 return
2976 }
2977 if errors.Is(err, errChatNotFound) {
2978 httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
2979 Message: "Chat not found.",
2980 })
2981 return
2982 }
2983 if errors.Is(err, errChatDoesNotBelongToAgent) {
2984 httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
2985 Message: "Chat does not belong to this agent.",
2986 })
2987 return
2988 }
2989 if errors.Is(err, errChatDoesNotBelongToWorkspaceOwner) {
2990 httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
2991 Message: "Chat does not belong to this workspace owner.",
2992 })
2993 return
2994 }
2995 if errors.Is(err, errChatNotActive) {
2996 httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
2997 Message: "Cannot modify context: this chat is no longer active.",
2998 })
2999 return
3000 }
3001
3002 var multipleErr *multipleActiveChatsError
3003 if errors.As(err, &multipleErr) {
3004 httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
3005 Message: err.Error(),
3006 })
3007 return
3008 }
3009
3010 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
3011 Message: "Failed to resolve chat.",
3012 Detail: err.Error(),
3013 })
3014}

Calls 4

WriteFunction · 0.92
AsMethod · 0.80
IsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected