From 81da804761d4e75916cd25336b3b19443c3c2311 Mon Sep 17 00:00:00 2001 From: Jordan Wright Date: Sun, 7 Oct 2018 12:37:15 -0500 Subject: [PATCH] Properly returning 404 error if the requested sending profile isn't found. --- models/smtp.go | 1 + models/smtp_test.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/models/smtp.go b/models/smtp.go index 996aac70..ea7d4c23 100644 --- a/models/smtp.go +++ b/models/smtp.go @@ -146,6 +146,7 @@ func GetSMTP(id int64, uid int64) (SMTP, error) { err := db.Where("user_id=? and id=?", uid, id).Find(&s).Error if err != nil { log.Error(err) + return s, err } err = db.Where("smtp_id=?", s.Id).Find(&s.Headers).Error if err != nil && err != gorm.ErrRecordNotFound { diff --git a/models/smtp_test.go b/models/smtp_test.go index 501407f6..ecf17f58 100644 --- a/models/smtp_test.go +++ b/models/smtp_test.go @@ -3,6 +3,8 @@ package models import ( "fmt" + "github.com/jinzhu/gorm" + check "gopkg.in/check.v1" ) @@ -74,3 +76,8 @@ func (s *ModelsSuite) TestSMTPGetDialer(ch *check.C) { ch.Assert(dialer.TLSConfig.ServerName, check.Equals, smtp.Host) ch.Assert(dialer.TLSConfig.InsecureSkipVerify, check.Equals, smtp.IgnoreCertErrors) } + +func (s *ModelsSuite) TestGetInvalidSMTP(ch *check.C) { + _, err := GetSMTP(-1, 1) + ch.Assert(err, check.Equals, gorm.ErrRecordNotFound) +}