mirror of
				https://github.com/KevinMidboe/planetposen-images.git
				synced 2025-10-29 13:20:11 +00:00 
			
		
		
		
	App for fetching and uploading images to cloud bucket storage
This commit is contained in:
		
							
								
								
									
										24
									
								
								server/handler/error.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								server/handler/error.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | ||||
| package handler | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"net/http" | ||||
|  | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| ) | ||||
|  | ||||
| // handleError - Logs the error (if shouldLog is true), and outputs the error message (msg) | ||||
| func handleError(w http.ResponseWriter, err error, msg string, statusCode int, shouldLog bool) { | ||||
| 	if shouldLog { | ||||
| 		log.WithField("err", err).Error(msg) | ||||
| 	} | ||||
|  | ||||
| 	w.Header().Set("Content-Type", "application/json") | ||||
| 	w.WriteHeader(statusCode) | ||||
| 	errorJSON, _ := json.Marshal(struct { | ||||
| 		Error string `json:"error"` | ||||
| 	}{ | ||||
| 		Error: msg, | ||||
| 	}) | ||||
| 	w.Write(errorJSON) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user