From d6f60ce24e123ee83b73f6c9dbe8c4b9af5c629e Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Sun, 9 Oct 2022 18:32:38 -0400 Subject: Improve error handling when file does not exist --- cmd/server/auth.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cmd/server/auth.go') diff --git a/cmd/server/auth.go b/cmd/server/auth.go index 5e2316e..635b6e2 100644 --- a/cmd/server/auth.go +++ b/cmd/server/auth.go @@ -4,10 +4,11 @@ import ( "crypto/rand" "encoding/base64" "encoding/json" + "errors" "fmt" + "io/fs" "net/http" "os" - "strings" "riedstra.dev/mitch/go-website/users" ) @@ -59,8 +60,7 @@ func (a *App) ReadAuth(fn string) error { //nolint fh, err := os.Open(fn) if err != nil { - if strings.Contains(err.Error(), "no such file") || - strings.Contains(err.Error(), "system cannot find the file specified") { + if errors.Is(err, fs.ErrNotExist) { goto write } -- cgit v1.2.3