writeAppStoreError maps an appstore refusal to its response.
(w http.ResponseWriter, err error)
| 109 | |
| 110 | // writeAppStoreError maps an appstore refusal to its response. |
| 111 | func 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 | |
| 144 | func (s *Server) appCreateItem(w http.ResponseWriter, r *http.Request) { |
| 145 | ac := appContextFrom(r) |