[Groonga-commit] groonga/grnci at 4555beb [master] Simplify DB.RequestCancel.

Back to archive index

Susumu Yata null+****@clear*****
Tue Sep 12 12:40:23 JST 2017


Susumu Yata	2017-09-12 12:40:23 +0900 (Tue, 12 Sep 2017)

  New Revision: 4555beb9ffb2dbc024958adc8655b665708866f4
  https://github.com/groonga/grnci/commit/4555beb9ffb2dbc024958adc8655b665708866f4

  Message:
    Simplify DB.RequestCancel.
    
    Ref: #42

  Modified files:
    v2/db.go

  Modified: v2/db.go (+13 -8)
===================================================================
--- v2/db.go    2017-09-12 12:31:25 +0900 (dfb9878)
+++ v2/db.go    2017-09-12 12:40:23 +0900 (5c50aac)
@@ -1364,17 +1364,20 @@ func (db *DB) Restore(r io.Reader, w io.Writer, stopOnError bool) (n int, err er
 }
 
 // RequestCancel executes request_cancel.
-func (db *DB) RequestCancel(id int) (bool, Response, error) {
+func (db *DB) RequestCancel(id int) error {
 	resp, err := db.Invoke("request_cancel", map[string]interface{}{
 		"id": id,
 	}, nil)
 	if err != nil {
-		return false, nil, err
+		return err
 	}
 	defer resp.Close()
+	if resp.Err() != nil {
+		return resp.Err()
+	}
 	jsonData, err := ioutil.ReadAll(resp)
 	if err != nil {
-		return false, resp, err
+		return err
 	}
 	type Result struct {
 		ID       int  `json:"id"`
@@ -1382,14 +1385,16 @@ func (db *DB) RequestCancel(id int) (bool, Response, error) {
 	}
 	var result Result
 	if err := json.Unmarshal(jsonData, &result); err != nil {
-		if resp.Err() != nil {
-			return false, resp, nil
-		}
-		return false, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{
+		return NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{
 			"error": err.Error(),
 		})
 	}
-	return result.Canceled, resp, nil
+	if !result.Canceled {
+		return NewError(ResponseError, "The request does not exist.", map[string]interface{}{
+			"id": result.ID,
+		})
+	}
+	return nil
 }
 
 // RubyEval executes ruby_eval.
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20170912/4528d4b9/attachment-0001.htm 



More information about the Groonga-commit mailing list
Back to archive index