Handle internal server error using new custom template
This commit is contained in:
@ -85,7 +85,8 @@ func init() {
|
|||||||
|
|
||||||
func GET(w http.ResponseWriter, r *http.Request) {
|
func GET(w http.ResponseWriter, r *http.Request) {
|
||||||
if _, ok := CsrfTokens[r.URL.Query().Get("state")]; !ok {
|
if _, ok := CsrfTokens[r.URL.Query().Get("state")]; !ok {
|
||||||
http.Error(w, "csrf token mismatch", http.StatusInternalServerError)
|
//csrf token mismatch error
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,16 +107,16 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
resp, err := http.Post("https://oauth2.googleapis.com/token", "application/x-www-form-urlencoded", bytes.NewBufferString(formData.Encode()))
|
resp, err := http.Post("https://oauth2.googleapis.com/token", "application/x-www-form-urlencoded", bytes.NewBufferString(formData.Encode()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error("Error:", err)
|
log.Error("Error:", err)
|
||||||
http.Error(w, "Failed to get token", http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
var oauthData OauthToken
|
var oauthData OauthToken
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&oauthData); err != nil {
|
if err := json.NewDecoder(resp.Body).Decode(&oauthData); err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error("Error reading token response body:", err)
|
log.Error("Error reading token response body:", err)
|
||||||
http.Error(w, "Failed to read token response body", http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,8 +125,8 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
req, err := http.NewRequest("GET", "https://www.googleapis.com/oauth2/v1/userinfo?alt=json", nil)
|
req, err := http.NewRequest("GET", "https://www.googleapis.com/oauth2/v1/userinfo?alt=json", nil)
|
||||||
req.Header.Set("Authorization", "Bearer "+oauthData.AccessToken)
|
req.Header.Set("Authorization", "Bearer "+oauthData.AccessToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error("Error creating user info request:", err)
|
log.Error("Error creating user info request:", err)
|
||||||
http.Error(w, "Failed to create user info request", http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,14 +135,14 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
var oauthUser OauthUser
|
var oauthUser OauthUser
|
||||||
if err := json.NewDecoder(userInfoResp.Body).Decode(&oauthUser); err != nil {
|
if err := json.NewDecoder(userInfoResp.Body).Decode(&oauthUser); err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error("Error reading user info response body:", err)
|
log.Error("Error reading user info response body:", err)
|
||||||
http.Error(w, "Failed to read user info response body", http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if oauthUser.Email == "" {
|
if oauthUser.Email == "" {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error("Error reading user info response body: email not found")
|
log.Error("Error reading user info response body: email not found")
|
||||||
http.Error(w, "Invalid email is given", http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,7 +160,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
user, err := cache.GetUser(oauthUser.Email)
|
user, err := cache.GetUser(oauthUser.Email)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,24 @@ package googleOauthHandler
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
googleOauthCallbackHandler "github.com/fossyy/filekeeper/handler/auth/google/callback"
|
googleOauthCallbackHandler "github.com/fossyy/filekeeper/handler/auth/google/callback"
|
||||||
|
"github.com/fossyy/filekeeper/logger"
|
||||||
"github.com/fossyy/filekeeper/utils"
|
"github.com/fossyy/filekeeper/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var log *logger.AggregatedLogger
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
log = logger.Logger()
|
||||||
|
}
|
||||||
|
|
||||||
func GET(w http.ResponseWriter, r *http.Request) {
|
func GET(w http.ResponseWriter, r *http.Request) {
|
||||||
token, err := utils.GenerateCSRFToken()
|
token, err := utils.GenerateCSRFToken()
|
||||||
googleOauthCallbackHandler.CsrfTokens[token] = &googleOauthCallbackHandler.CsrfToken{Token: token, CreateTime: time.Now()}
|
googleOauthCallbackHandler.CsrfTokens[token] = &googleOauthCallbackHandler.CsrfToken{Token: token, CreateTime: time.Now()}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
http.Redirect(w, r, fmt.Sprintf("https://accounts.google.com/o/oauth2/auth?scope=email profile&response_type=code&access_type=offline&state=%s&redirect_uri=%s&client_id=%s", token, utils.Getenv("GOOGLE_CALLBACK"), utils.Getenv("GOOGLE_CLIENT_ID")), http.StatusFound)
|
http.Redirect(w, r, fmt.Sprintf("https://accounts.google.com/o/oauth2/auth?scope=email profile&response_type=code&access_type=offline&state=%s&redirect_uri=%s&client_id=%s", token, utils.Getenv("GOOGLE_CALLBACK"), utils.Getenv("GOOGLE_CLIENT_ID")), http.StatusFound)
|
||||||
|
@ -67,7 +67,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
err := component.Render(r.Context(), w)
|
err := component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
err := r.ParseForm()
|
err := r.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
err := component.Render(r.Context(), w)
|
err := component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
err := component.Render(r.Context(), w)
|
err := component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
userSession := r.Context().Value("user").(types.User)
|
userSession := r.Context().Value("user").(types.User)
|
||||||
files, err := db.DB.GetFiles(userSession.UserID.String())
|
files, err := db.DB.GetFiles(userSession.UserID.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
component := downloadView.Main("Download Page", filesData)
|
component := downloadView.Main("Download Page", filesData)
|
||||||
err = component.Render(r.Context(), w)
|
err = component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
fileID := r.PathValue("id")
|
fileID := r.PathValue("id")
|
||||||
file, err := db.DB.GetFile(fileID)
|
file, err := db.DB.GetFile(fileID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -32,13 +32,13 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if filepath.Dir(saveFolder) != filepath.Join(basePath, file.OwnerID.String()) {
|
if filepath.Dir(saveFolder) != filepath.Join(basePath, file.OwnerID.String()) {
|
||||||
log.Error("invalid path")
|
log.Error("invalid path")
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
openFile, err := os.OpenFile(filepath.Join(saveFolder, file.Name), os.O_RDONLY, 0)
|
openFile, err := os.OpenFile(filepath.Join(saveFolder, file.Name), os.O_RDONLY, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
stat, err := openFile.Stat()
|
stat, err := openFile.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package errorHandler
|
package errorHandler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/fossyy/filekeeper/logger"
|
"github.com/fossyy/filekeeper/logger"
|
||||||
@ -17,7 +18,7 @@ func NotFound(w http.ResponseWriter, r *http.Request) {
|
|||||||
component := errorView.NotFound("Not Found")
|
component := errorView.NotFound("Not Found")
|
||||||
err := component.Render(r.Context(), w)
|
err := component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
fmt.Fprint(w, err.Error())
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -27,7 +28,7 @@ func InternalServerError(w http.ResponseWriter, r *http.Request) {
|
|||||||
component := errorView.InternalServerError("Internal Server Error")
|
component := errorView.InternalServerError("Internal Server Error")
|
||||||
err := component.Render(r.Context(), w)
|
err := component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
fmt.Fprint(w, err.Error())
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
err := component.Render(r.Context(), w)
|
err := component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
err := component.Render(r.Context(), w)
|
err := component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
err = verifyForgot(userData)
|
err = verifyForgot(userData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
component := forgotPasswordView.EmailSend("Forgot Password Page")
|
component := forgotPasswordView.EmailSend("Forgot Password Page")
|
||||||
err = component.Render(r.Context(), w)
|
err = component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
err := component.Render(r.Context(), w)
|
err := component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
err := r.ParseForm()
|
err := r.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
err := component.Render(r.Context(), w)
|
err := component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -81,14 +81,14 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
hashedPassword, err := utils.HashPassword(password)
|
hashedPassword, err := utils.HashPassword(password)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.DB.UpdateUserPassword(data.User.Email, hashedPassword)
|
err = db.DB.UpdateUserPassword(data.User.Email, hashedPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
component := forgotPasswordView.ChangeSuccess("Forgot Password Page")
|
component := forgotPasswordView.ChangeSuccess("Forgot Password Page")
|
||||||
err = component.Render(r.Context(), w)
|
err = component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
component := indexView.Main("main page", userSession)
|
component := indexView.Main("main page", userSession)
|
||||||
err := component.Render(r.Context(), w)
|
err := component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
if errors.Is(err, &session.SessionNotFoundError{}) {
|
if errors.Is(err, &session.SessionNotFoundError{}) {
|
||||||
storeSession.Destroy(w)
|
storeSession.Destroy(w)
|
||||||
}
|
}
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
err := component.Render(r.Context(), w)
|
err := component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
err = component.Render(r.Context(), w)
|
err = component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
err = component.Render(r.Context(), w)
|
err = component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
err := component.Render(r.Context(), w)
|
err := component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
func POST(w http.ResponseWriter, r *http.Request) {
|
func POST(w http.ResponseWriter, r *http.Request) {
|
||||||
err := r.ParseForm()
|
err := r.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
err := component.Render(r.Context(), w)
|
err := component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
err = component.Render(r.Context(), w)
|
err = component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
err = verifyEmail(&newUser)
|
err = verifyEmail(&newUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
component := signupView.EmailSend("Sign up Page")
|
component := signupView.EmailSend("Sign up Page")
|
||||||
err = component.Render(r.Context(), w)
|
err = component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
err := component.Render(r.Context(), w)
|
err := component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
err = component.Render(r.Context(), w)
|
err = component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ func init() {
|
|||||||
func GET(w http.ResponseWriter, r *http.Request) {
|
func GET(w http.ResponseWriter, r *http.Request) {
|
||||||
component := filesView.Main("upload page")
|
component := filesView.Main("upload page")
|
||||||
if err := component.Render(r.Context(), w); err != nil {
|
if err := component.Render(r.Context(), w); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29,7 +29,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
func POST(w http.ResponseWriter, r *http.Request) {
|
func POST(w http.ResponseWriter, r *http.Request) {
|
||||||
fileID := r.PathValue("id")
|
fileID := r.PathValue("id")
|
||||||
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
if _, err := os.Stat(uploadDir); os.IsNotExist(err) {
|
if _, err := os.Stat(uploadDir); os.IsNotExist(err) {
|
||||||
if err := os.Mkdir(uploadDir, os.ModePerm); err != nil {
|
if err := os.Mkdir(uploadDir, os.ModePerm); err != nil {
|
||||||
log.Error("error getting upload info: " + err.Error())
|
log.Error("error getting upload info: " + err.Error())
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
file, err := cache.GetFile(fileID)
|
file, err := cache.GetFile(fileID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("error getting upload info: " + err.Error())
|
log.Error("error getting upload info: " + err.Error())
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,14 +57,14 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if filepath.Dir(saveFolder) != filepath.Join(basePath, userSession.UserID.String()) {
|
if filepath.Dir(saveFolder) != filepath.Join(basePath, userSession.UserID.String()) {
|
||||||
log.Error("invalid path")
|
log.Error("invalid path")
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fileByte, fileHeader, err := r.FormFile("chunk")
|
fileByte, fileHeader, err := r.FormFile("chunk")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("error getting upload info: " + err.Error())
|
log.Error("error getting upload info: " + err.Error())
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer fileByte.Close()
|
defer fileByte.Close()
|
||||||
@ -80,14 +80,14 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
|||||||
dst, err := os.OpenFile(filepath.Join(saveFolder, file.Name), os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
|
dst, err := os.OpenFile(filepath.Join(saveFolder, file.Name), os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("error making upload folder: " + err.Error())
|
log.Error("error making upload folder: " + err.Error())
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
defer dst.Close()
|
defer dst.Close()
|
||||||
if _, err := io.Copy(dst, fileByte); err != nil {
|
if _, err := io.Copy(dst, fileByte); err != nil {
|
||||||
log.Error("error copying byte to file dst: " + err.Error())
|
log.Error("error copying byte to file dst: " + err.Error())
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
|||||||
component := userView.Main("User Page", userSession, session.GetSessions(userSession.Email))
|
component := userView.Main("User Page", userSession, session.GetSessions(userSession.Email))
|
||||||
err := component.Render(r.Context(), w)
|
err := component.Render(r.Context(), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -25,20 +25,24 @@ type wrapper struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *wrapper) WriteHeader(code int) {
|
func (w *wrapper) WriteHeader(code int) {
|
||||||
switch code {
|
w.statusCode = code
|
||||||
case http.StatusNotFound:
|
|
||||||
|
if code == http.StatusNotFound {
|
||||||
w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
|
w.ResponseWriter.WriteHeader(code)
|
||||||
errorHandler.NotFound(w.ResponseWriter, w.request)
|
errorHandler.NotFound(w.ResponseWriter, w.request)
|
||||||
return
|
return
|
||||||
case http.StatusInternalServerError:
|
}
|
||||||
|
|
||||||
|
if code == http.StatusInternalServerError {
|
||||||
w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
|
w.ResponseWriter.WriteHeader(code)
|
||||||
errorHandler.InternalServerError(w.ResponseWriter, w.request)
|
errorHandler.InternalServerError(w.ResponseWriter, w.request)
|
||||||
return
|
return
|
||||||
default:
|
|
||||||
w.ResponseWriter.WriteHeader(code)
|
|
||||||
w.statusCode = code
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
w.ResponseWriter.WriteHeader(code)
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func Handler(next http.Handler) http.Handler {
|
func Handler(next http.Handler) http.Handler {
|
||||||
|
@ -36,7 +36,7 @@ templ NotFound(title string){
|
|||||||
|
|
||||||
templ InternalServerError(title string){
|
templ InternalServerError(title string){
|
||||||
@layout.Base(title){
|
@layout.Base(title){
|
||||||
<main class="container mx-auto px-4 py-12 md:px-6 md:py-16 lg:py-10">
|
<main class="container mx-auto px-4 md:px-6">
|
||||||
<div class="flex h-screen w-full flex-col items-center justify-center bg-white">
|
<div class="flex h-screen w-full flex-col items-center justify-center bg-white">
|
||||||
<image class="w-32 md:w-64 lg:w-128" src="/public/InternalServerErrorIcon.svg" alt="brand image" />
|
<image class="w-32 md:w-64 lg:w-128" src="/public/InternalServerErrorIcon.svg" alt="brand image" />
|
||||||
<div class="mx-auto max-w-md space-y-4 text-center">
|
<div class="mx-auto max-w-md space-y-4 text-center">
|
||||||
|
Reference in New Issue
Block a user