@@ -51,6 +51,15 @@ func getRequestID(ctx context.Context) string {
5151
5252const lfsMediaType = "application/vnd.git-lfs+json"
5353
54+ // msgInternalError is the generic message returned to clients for unexpected server-side failures.
55+ const msgInternalError = "internal error"
56+
57+ // URL schemes used when constructing external base URLs.
58+ const (
59+ schemeHTTP = "http"
60+ schemeHTTPS = "https"
61+ )
62+
5463// LFS operation names used in batch requests.
5564const (
5665 opDownload = "download"
@@ -213,7 +222,7 @@ func (h *Handler) DownloadHandler(w http.ResponseWriter, r *http.Request) {
213222 writeError (w , r , http .StatusNotFound , "object not found" )
214223 } else {
215224 log .Error ().Err (err ).Str ("oid" , oid ).Msg ("reading object" )
216- writeError (w , r , http .StatusInternalServerError , "internal error" )
225+ writeError (w , r , http .StatusInternalServerError , msgInternalError )
217226 }
218227 return
219228 }
@@ -275,7 +284,7 @@ func (h *Handler) UploadHandler(w http.ResponseWriter, r *http.Request) {
275284 exists , err := h .store .Exists (r .Context (), h .endpoint .Path , oid )
276285 if err != nil {
277286 log .Error ().Err (err ).Str ("oid" , oid ).Msg ("checking object existence" )
278- writeError (w , r , http .StatusInternalServerError , "internal error" )
287+ writeError (w , r , http .StatusInternalServerError , msgInternalError )
279288 return
280289 }
281290 if exists {
@@ -296,7 +305,7 @@ func (h *Handler) UploadHandler(w http.ResponseWriter, r *http.Request) {
296305 return
297306 }
298307 log .Error ().Err (err ).Str ("oid" , oid ).Msg ("storing object" )
299- writeError (w , r , http .StatusInternalServerError , "internal error" )
308+ writeError (w , r , http .StatusInternalServerError , msgInternalError )
300309 return
301310 }
302311
@@ -342,7 +351,7 @@ func (h *Handler) VerifyHandler(w http.ResponseWriter, r *http.Request) {
342351 writeError (w , r , http .StatusNotFound , "object not found" )
343352 } else {
344353 log .Error ().Err (err ).Str ("oid" , req .OID ).Msg ("checking object size" )
345- writeError (w , r , http .StatusInternalServerError , "internal error" )
354+ writeError (w , r , http .StatusInternalServerError , msgInternalError )
346355 }
347356 return
348357 }
@@ -391,7 +400,7 @@ func (h *Handler) CreateLockHandler(w http.ResponseWriter, r *http.Request) {
391400 return
392401 }
393402 log .Error ().Err (err ).Str ("endpoint" , h .endpoint .Name ).Msg ("creating lock" )
394- writeError (w , r , http .StatusInternalServerError , "internal error" )
403+ writeError (w , r , http .StatusInternalServerError , msgInternalError )
395404 return
396405 }
397406
@@ -433,7 +442,7 @@ func (h *Handler) ListLocksHandler(w http.ResponseWriter, r *http.Request) {
433442 })
434443 if err != nil {
435444 log .Error ().Err (err ).Str ("endpoint" , h .endpoint .Name ).Msg ("listing locks" )
436- writeError (w , r , http .StatusInternalServerError , "internal error" )
445+ writeError (w , r , http .StatusInternalServerError , msgInternalError )
437446 return
438447 }
439448
@@ -470,7 +479,7 @@ func (h *Handler) VerifyLocksHandler(w http.ResponseWriter, r *http.Request) {
470479 })
471480 if err != nil {
472481 log .Error ().Err (err ).Str ("endpoint" , h .endpoint .Name ).Msg ("verifying locks" )
473- writeError (w , r , http .StatusInternalServerError , "internal error" )
482+ writeError (w , r , http .StatusInternalServerError , msgInternalError )
474483 return
475484 }
476485
@@ -528,7 +537,7 @@ func (h *Handler) UnlockHandler(w http.ResponseWriter, r *http.Request) {
528537 return
529538 }
530539 log .Error ().Err (err ).Str ("endpoint" , h .endpoint .Name ).Msg ("unlocking" )
531- writeError (w , r , http .StatusInternalServerError , "internal error" )
540+ writeError (w , r , http .StatusInternalServerError , msgInternalError )
532541 return
533542 }
534543
@@ -558,7 +567,7 @@ func (h *Handler) requireAuthResult(w http.ResponseWriter, r *http.Request, op a
558567 result , err := h .authenticate (r , op )
559568 if err != nil {
560569 log .Error ().Err (err ).Str ("endpoint" , h .endpoint .Name ).Msg ("authentication error" )
561- writeError (w , r , http .StatusInternalServerError , "internal error" )
570+ writeError (w , r , http .StatusInternalServerError , msgInternalError )
562571 return auth.Result {}, false
563572 }
564573 if ! result .Authenticated {
@@ -631,11 +640,11 @@ func (h *Handler) requestBaseURL(r *http.Request) string {
631640 if h .baseURL != "" {
632641 return h .baseURL
633642 }
634- scheme := "http"
643+ scheme := schemeHTTP
635644 if r .TLS != nil {
636- scheme = "https"
645+ scheme = schemeHTTPS
637646 }
638- if proto := r .Header .Get ("X-Forwarded-Proto" ); proto == "http" || proto == "https" {
647+ if proto := r .Header .Get ("X-Forwarded-Proto" ); proto == schemeHTTP || proto == schemeHTTPS {
639648 scheme = proto
640649 }
641650 host := r .Host
@@ -689,7 +698,7 @@ func writeJSON(w http.ResponseWriter, status int, v any) {
689698 data , err := json .Marshal (v )
690699 if err != nil {
691700 log .Error ().Err (err ).Msg ("marshalling JSON response" )
692- http .Error (w , "internal error" , http .StatusInternalServerError )
701+ http .Error (w , msgInternalError , http .StatusInternalServerError )
693702 return
694703 }
695704 w .Header ().Set ("Content-Type" , lfsMediaType )
0 commit comments