mirror of
				https://github.com/3ybactuk/marketplace-go-service-project.git
				synced 2025-10-30 14:03:45 +03:00 
			
		
		
		
	
		
			
				
	
	
		
			25 lines
		
	
	
		
			447 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			447 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package server
 | |
| 
 | |
| import (
 | |
| 	"encoding/json"
 | |
| 	"net/http"
 | |
| 
 | |
| 	"github.com/rs/zerolog/log"
 | |
| )
 | |
| 
 | |
| func makeErrorResponse(w http.ResponseWriter, err error, statusCode int) {
 | |
| 	type ErrorMessage struct {
 | |
| 		Message string
 | |
| 	}
 | |
| 
 | |
| 	w.Header().Add("Content-Type", "application/json")
 | |
| 	w.WriteHeader(statusCode)
 | |
| 
 | |
| 	errResponse := &ErrorMessage{Message: err.Error()}
 | |
| 	if errE := json.NewEncoder(w).Encode(errResponse); errE != nil {
 | |
| 		log.Err(errE).Send()
 | |
| 
 | |
| 		return
 | |
| 	}
 | |
| }
 | 
