github.com/hoffie/larasync@v0.0.0-20151025221940-0384d2bddcef/api/server/error.go (about)

     1  package server
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"encoding/json"
     7  
     8  	"github.com/hoffie/larasync/api"
     9  )
    10  
    11  func errorJSONMessage(w http.ResponseWriter, error string, code int) {
    12  	errorObj := &api.JSONError{
    13  		Error: error,
    14  		Type:  "generic",
    15  	}
    16  	errorJSON(w, errorObj, code)
    17  }
    18  
    19  func errorJSON(w http.ResponseWriter, jsonError interface{}, code int) {
    20  	w.Header().Set("Content-Type", "application/json")
    21  	w.WriteHeader(code)
    22  	data, _ := json.Marshal(jsonError)
    23  	w.Write(data)
    24  }
    25  
    26  func errorText(w http.ResponseWriter, error string, code int) {
    27  	w.Header().Set("Content-Type", "plain/text")
    28  	w.WriteHeader(code)
    29  	w.Write([]byte(error))
    30  }