Centralizing error handling to a helpers package
This commit is contained in:
		@ -5,9 +5,9 @@ import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"go-udemy-web-1/internal/config"
 | 
			
		||||
	"go-udemy-web-1/internal/helpers"
 | 
			
		||||
	"go-udemy-web-1/internal/models"
 | 
			
		||||
	"html/template"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
 | 
			
		||||
@ -59,14 +59,14 @@ func RenderTemplate(w http.ResponseWriter, r *http.Request, tmpl string, td *mod
 | 
			
		||||
 | 
			
		||||
	err := t.Execute(buf, td)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Println(err)
 | 
			
		||||
		helpers.ServerError(w, err)
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// render the template
 | 
			
		||||
	_, err = buf.WriteTo(w)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Println(err)
 | 
			
		||||
		helpers.ServerError(w, err)
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -4,6 +4,7 @@ import (
 | 
			
		||||
	"encoding/gob"
 | 
			
		||||
	"go-udemy-web-1/internal/config"
 | 
			
		||||
	"go-udemy-web-1/internal/models"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"os"
 | 
			
		||||
	"testing"
 | 
			
		||||
@ -32,6 +33,12 @@ func TestMain(m *testing.M) {
 | 
			
		||||
 | 
			
		||||
	testApp.Session = session
 | 
			
		||||
 | 
			
		||||
	infoLog := log.New(os.Stdout, "INFO\t", log.Ldate|log.Ltime)
 | 
			
		||||
	testApp.InfoLog = infoLog
 | 
			
		||||
 | 
			
		||||
	errorLog := log.New(os.Stdout, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile)
 | 
			
		||||
	testApp.ErrorLog = errorLog
 | 
			
		||||
 | 
			
		||||
	app = &testApp
 | 
			
		||||
 | 
			
		||||
	os.Exit(m.Run())
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user