Skip to content

Commit

Permalink
jutils improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
karnthis committed Sep 13, 2023
1 parent 4d9a7a6 commit 6dc1b21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
11 changes: 3 additions & 8 deletions jutils/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@ import (

func ProcessError(block string, caughtError error) {
fmt.Printf("***** Error in block: %s *****\n", block)
fmt.Printf("***** Stamp: %s *****\n", FriendlyTimestamp())
fmt.Println(caughtError)
fmt.Println("***** End Error Report *****")
}

func ProcessHttpError(block string, caughtError error, eCode int, w http.ResponseWriter) {
fmt.Printf("***** Error in block: %s *****\n", block)
fmt.Println(caughtError)
fmt.Println("***** End Error Report *****")
w.WriteHeader(eCode)
_, err := w.Write([]byte(caughtError.Error()))
if err != nil {
ProcessError(fmt.Sprintf("processHttpPostError for %s", block), err)
}
ProcessError(block, caughtError)
http.Error(w, caughtError.Error(), eCode)
}

func ProcessCustomHttpError(block string, customError string, eCode int, w http.ResponseWriter) error {
Expand Down
17 changes: 17 additions & 0 deletions jutils/time.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package jutils

import (
"fmt"
"time"
)

func FriendlyTimestamp() string {
currentTime := time.Now()
return fmt.Sprintf("%d-%d-%d %d:%d:%d\n",
currentTime.Year(),
currentTime.Month(),
currentTime.Day(),
currentTime.Hour(),
currentTime.Minute(),
currentTime.Second())
}

0 comments on commit 6dc1b21

Please sign in to comment.