mirror of
https://github.com/pikami/cosmium.git
synced 2026-06-12 15:27:06 +01:00
Expose precondition error code header
Co-authored-by: Pijus Kamandulis <pikami@users.noreply.github.com>
This commit is contained in:
@@ -105,6 +105,7 @@ func (h *Handlers) ReplaceDocument(c *gin.Context) {
|
|||||||
|
|
||||||
if ifMatch := c.GetHeader(headers.IfMatch); ifMatch != "" {
|
if ifMatch := c.GetHeader(headers.IfMatch); ifMatch != "" {
|
||||||
if existingDocument["_etag"] != ifMatch {
|
if existingDocument["_etag"] != ifMatch {
|
||||||
|
c.Header(headers.ErrorCode, "PreconditionFailed")
|
||||||
c.JSON(http.StatusPreconditionFailed, constants.PreconditionFailedResponse)
|
c.JSON(http.StatusPreconditionFailed, constants.PreconditionFailedResponse)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const (
|
|||||||
AIM = "A-Im"
|
AIM = "A-Im"
|
||||||
Authorization = "authorization"
|
Authorization = "authorization"
|
||||||
CosmosLsn = "x-ms-cosmos-llsn"
|
CosmosLsn = "x-ms-cosmos-llsn"
|
||||||
|
ErrorCode = "x-ms-error-code"
|
||||||
ETag = "etag"
|
ETag = "etag"
|
||||||
GlobalCommittedLsn = "x-ms-global-committed-lsn"
|
GlobalCommittedLsn = "x-ms-global-committed-lsn"
|
||||||
IfMatch = "if-match"
|
IfMatch = "if-match"
|
||||||
|
|||||||
@@ -403,7 +403,7 @@ func Test_Documents(t *testing.T) {
|
|||||||
var respErr *azcore.ResponseError
|
var respErr *azcore.ResponseError
|
||||||
if errors.As(err, &respErr) {
|
if errors.As(err, &respErr) {
|
||||||
assert.Equal(t, http.StatusPreconditionFailed, respErr.StatusCode)
|
assert.Equal(t, http.StatusPreconditionFailed, respErr.StatusCode)
|
||||||
assert.Equal(t, "PreconditionFailed", respErr.ErrorCode)
|
assert.Equal(t, "PreconditionFailed", respErr.RawResponse.Header.Get("x-ms-error-code"))
|
||||||
|
|
||||||
responseBody, readErr := io.ReadAll(respErr.RawResponse.Body)
|
responseBody, readErr := io.ReadAll(respErr.RawResponse.Body)
|
||||||
assert.Nil(t, readErr)
|
assert.Nil(t, readErr)
|
||||||
|
|||||||
Reference in New Issue
Block a user