[lxc-devel] [lxd/master] lxd/response: Simplify SmartError

stgraber on Github lxc-bot at linuxcontainers.org
Wed Mar 6 21:46:31 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190306/adba99cf/attachment.bin>
-------------- next part --------------
From bb0a66877a8c50af2492b10c0711f1a0568850ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 6 Mar 2019 16:43:05 -0500
Subject: [PATCH] lxd/response: Simplify SmartError
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/response.go | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/lxd/response.go b/lxd/response.go
index 62bcc9669f..b78ab96544 100644
--- a/lxd/response.go
+++ b/lxd/response.go
@@ -521,17 +521,11 @@ func SmartError(err error) Response {
 	switch errors.Cause(err) {
 	case nil:
 		return EmptySyncResponse
-	case os.ErrNotExist:
-		return NotFound(nil)
-	case sql.ErrNoRows:
-		return NotFound(nil)
-	case db.ErrNoSuchObject:
+	case os.ErrNotExist, sql.ErrNoRows, db.ErrNoSuchObject:
 		return NotFound(nil)
 	case os.ErrPermission:
 		return Forbidden(nil)
-	case db.ErrAlreadyDefined:
-		return Conflict(nil)
-	case sqlite3.ErrConstraintUnique:
+	case db.ErrAlreadyDefined, sqlite3.ErrConstraintUnique:
 		return Conflict(nil)
 	case dqlite.ErrNoAvailableLeader:
 		return Unavailable(err)


More information about the lxc-devel mailing list