HTTP handler for a DELETE of a document
()
| 798 | |
| 799 | // HTTP handler for a DELETE of a document |
| 800 | func (h *handler) handleDeleteDoc() error { |
| 801 | if h.db.DatabaseContext.Options.UnsupportedOptions != nil && h.db.DatabaseContext.Options.UnsupportedOptions.RejectWritesWithSkippedSequences { |
| 802 | // if we are in slow broadcast mode reject write with 503 and increment rejected writes stat |
| 803 | if h.db.BroadcastSlowMode.Load() { |
| 804 | h.db.DbStats.DatabaseStats.NumDocWritesRejected.Add(1) |
| 805 | return base.HTTPErrorf(http.StatusServiceUnavailable, "Database cache is behind and cannot accept writes at this time. Please try again later.") |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | docid := h.PathVar("docid") |
| 810 | |
| 811 | // occValue is the optimistic concurrency control value, which can be either the current rev ID or CV - used to prevent lost updates. |
| 812 | // we grab occValue from either query param, Etag header, or request body (in that order) |
| 813 | occValue, occValueType, err := h.getOCCValue(nil) |
| 814 | if err != nil { |
| 815 | return fmt.Errorf("couldn't get OCC value from request: %w", err) |
| 816 | } |
| 817 | |
| 818 | docVersion, err := docVersionFromOCCValue(occValue, occValueType) |
| 819 | if err != nil { |
| 820 | return fmt.Errorf("couldn't build document version from OCC value: %w", err) |
| 821 | } |
| 822 | |
| 823 | newRev, doc, err := h.collection.DeleteDoc(h.ctx(), docid, docVersion) |
| 824 | if err != nil { |
| 825 | return err |
| 826 | } |
| 827 | |
| 828 | respBody := []byte(`{"id":` + base.ConvertToJSONString(docid) + `,"ok":true,"rev":"` + newRev + `"}`) |
| 829 | if doc != nil { |
| 830 | respBody, err = base.InjectJSONProperties(respBody, base.KVPair{Key: "cv", Val: doc.HLV.GetCurrentVersionString()}) |
| 831 | if err != nil { |
| 832 | base.AssertfCtx(h.ctx(), "Failed to inject JSON properties: %v", err) |
| 833 | // safe to continue - we'll just have no deleted in response |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | h.writeRawJSONStatus(http.StatusOK, respBody) |
| 838 | return nil |
| 839 | } |
| 840 | |
| 841 | // ////// LOCAL DOCS: |
| 842 |
nothing calls this directly
no test coverage detected