github.com/Venafi/vcert/v5@v5.10.2/pkg/venafi/firefly/util_test.go (about)

     1  package firefly
     2  
     3  import (
     4  	"encoding/json"
     5  	"log"
     6  	"net/http"
     7  )
     8  
     9  func writeError(w http.ResponseWriter, statusCode int, error string, errorDescription string) {
    10  	w.WriteHeader(statusCode)
    11  	w.Header().Set("Content-Type", "application/json")
    12  	resp := make(map[string]string)
    13  	resp["error"] = error
    14  	if errorDescription != "" {
    15  		resp["error_description"] = errorDescription
    16  	}
    17  	jsonResp, err := json.Marshal(resp)
    18  	if err != nil {
    19  		log.Fatalf("Error happened in JSON marshal. Err: %s", err)
    20  	}
    21  	w.Write(jsonResp)
    22  }