forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
document_conflict_exception.go
33 lines (28 loc) · 1014 Bytes
/
document_conflict_exception.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package ravendb
// DocumentConflictError represents document conflict error from the server
type DocumentConflictError struct {
ConflictError
DocID string
LargestEtag int64
}
func newDocumentConflictError(message string, docID string, etag int64) *DocumentConflictError {
res := &DocumentConflictError{}
res.ConflictError = *newConflictError("%s", message)
res.DocID = docID
res.LargestEtag = etag
return res
}
func newDocumentConflictErrorFromMessage(message string) *DocumentConflictError {
return newDocumentConflictError(message, "", 0)
}
func newDocumentConflictErrorFromJSON(js string) error {
var jsonNode map[string]interface{}
err := jsonUnmarshal([]byte(js), &jsonNode)
if err != nil {
return newBadResponseError("Unable to parse server response: %s", err)
}
docID, _ := jsonGetAsText(jsonNode, "DocId")
message, _ := jsonGetAsText(jsonNode, "Message")
largestEtag, _ := jsonGetAsInt64(jsonNode, "LargestEtag")
return newDocumentConflictError(message, docID, largestEtag)
}