[lxc-devel] [lxd/master] lxd/response: Show wrapped errors

stgraber on Github lxc-bot at linuxcontainers.org
Wed Aug 14 00:09:40 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/20190813/0896937e/attachment.bin>
-------------- next part --------------
From 718f8d0263627ff20411feebb731c9f8544f115e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 13 Aug 2019 19:58:25 -0400
Subject: [PATCH] lxd/response: Show wrapped errors
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 | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lxd/response.go b/lxd/response.go
index 8e77e8d402..3b9e6fe9c9 100644
--- a/lxd/response.go
+++ b/lxd/response.go
@@ -524,10 +524,22 @@ func SmartError(err error) Response {
 
 	switch errors.Cause(err) {
 	case os.ErrNotExist, sql.ErrNoRows, db.ErrNoSuchObject:
+		if errors.Cause(err) != err {
+			return NotFound(err)
+		}
+
 		return NotFound(nil)
 	case os.ErrPermission:
+		if errors.Cause(err) != err {
+			return Forbidden(err)
+		}
+
 		return Forbidden(nil)
 	case db.ErrAlreadyDefined, sqlite3.ErrConstraintUnique:
+		if errors.Cause(err) != err {
+			return Conflict(err)
+		}
+
 		return Conflict(nil)
 	case dqlite.ErrNoAvailableLeader:
 		return Unavailable(err)


More information about the lxc-devel mailing list