MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / writeAppStoreError

Function writeAppStoreError

internal/server/app_api_write.go:111–142  ·  view source on GitHub ↗

writeAppStoreError maps an appstore refusal to its response.

(w http.ResponseWriter, err error)

Source from the content-addressed store, hash-verified

109
110// writeAppStoreError maps an appstore refusal to its response.
111func writeAppStoreError(w http.ResponseWriter, err error) {
112 if writeAppAttachmentError(w, err) {
113 return
114 }
115 switch {
116 case appstore.IsInputError(err):
117 writeError(w, http.StatusBadRequest, "validation_error", err.Error())
118 case errors.Is(err, store.ErrFenceStale), errors.Is(err, store.ErrFenceClosed):
119 writeAppUnauthorized(w)
120 case errors.Is(err, store.ErrNotCompanion):
121 writeError(w, http.StatusForbidden, "forbidden", "This app may not write here")
122 case errors.Is(err, store.ErrAppNotAppItem):
123 writeError(w, http.StatusForbidden, "forbidden", "This app did not create this item")
124 case errors.Is(err, store.ErrAppETagMismatch):
125 writeError(w, http.StatusPreconditionFailed, "etag_mismatch", "The item changed; fetch it again")
126 case errors.Is(err, store.ErrAppItemLimit):
127 // No counts: the human renderer's totals are workspace-wide.
128 writeError(w, http.StatusForbidden, "item_limit_reached", "The workspace has reached its item limit")
129 case errors.Is(err, store.ErrAppCommentNotFound):
130 writeAppNotFound(w, "Comment")
131 case errors.Is(err, store.ErrAppNotCommentAuthor):
132 writeError(w, http.StatusForbidden, "forbidden", "Only the comment's author may change it")
133 case errors.Is(err, store.ErrCommentDeleted):
134 writeError(w, http.StatusConflict, "comment_deleted", "The comment was deleted")
135 case errors.Is(err, store.ErrAppAttachmentUnavailable):
136 writeError(w, http.StatusUnprocessableEntity, "attachment_unavailable", "An attachment reference is not available")
137 case errors.Is(err, store.ErrAppCrossItemThread):
138 writeError(w, http.StatusConflict, "cross_item_thread", "The comment's thread leaves this item")
139 default:
140 writeInternalError(w, err)
141 }
142}
143
144func (s *Server) appCreateItem(w http.ResponseWriter, r *http.Request) {
145 ac := appContextFrom(r)

Callers 9

appCreateItemMethod · 0.85
appUpdateItemMethod · 0.85
appCreateCommentMethod · 0.85
appUpdateCommentMethod · 0.85
appDeleteCommentMethod · 0.85
appUploadAttachmentMethod · 0.85
appGetAttachmentMethod · 0.85
appDownloadAttachmentMethod · 0.85

Calls 8

IsInputErrorFunction · 0.92
writeAppAttachmentErrorFunction · 0.85
writeErrorFunction · 0.85
writeAppUnauthorizedFunction · 0.85
writeAppNotFoundFunction · 0.85
writeInternalErrorFunction · 0.85
ErrorMethod · 0.45
IsMethod · 0.45