Send email on exception or error inside the code

I would like to send email if there is any error in the application.
.go file name with line number with exception.

this will help us lot

Hi, I don’t recommend this. Why do you not use normal logging instead? If your issue is with the line number and you sometimes need a long time of searching, I had the problem as well.

My code is below for http error response, but you can use something similar and always find the cause of the error instantly.

type ErrorResponse struct {
	Detail string `json:"detail"` // This is my own commend, on what caused the error.
	Error  string `json:"error"`
}

	userpermissions, err := app.Queries.GetPurePermissionsByUserId(context.Background(), user.ID)
	if err != nil {
		utils.RespondWithJSON(w, utils.ErrorResponse{
			Detail: "Error getting permissions for user",
			Error:  err.Error(),
		})
		return
	}
1 Like

Thank you so much . if there is any unhandled exception

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.