Example #1
0
func mapErrorToHttpResponse(err errors.Error) int {
	switch err.Code() {
	case 1000: // readonly violation
		return http.StatusForbidden
	case 1010: // unsupported http method
		return http.StatusMethodNotAllowed
	case 1020, 1030, 1040, 1050, 1060, 1070:
		return http.StatusBadRequest
	case 3000: // parse error range
		return http.StatusBadRequest
	case 4000: // plan error range
		return http.StatusNotFound
	case 5000:
		return http.StatusInternalServerError
	default:
		return http.StatusInternalServerError
	}
}
Example #2
0
func (this *httpRequest) writeError(err errors.Error, count int) bool {
	var rv bool
	if count == 0 {
		rv = this.writeString("\n")
	} else {
		rv = this.writeString(",\n")
	}

	m := map[string]interface{}{
		"code": err.Code(),
		"msg":  err.Error(),
	}
	bytes, er := json.MarshalIndent(m, "        ", "    ")
	if er != nil {
		return false
	}

	return rv &&
		this.writeString("        ") &&
		this.writeString(string(bytes))
}