Ejemplo n.º 1
0
func (this *RespondWith) UnexpectedError(err api.Error) {
	if err.Any() {
		this.Error(http.StatusInternalServerError, err)
		return
	}

	this.Error(http.StatusInternalServerError, api.UserError("An unexpected error happened."))
}
Ejemplo n.º 2
0
func (this *RespondWith) Error(httpStatus int, err api.Error) {
	response := gin.H{
		"error_code": httpStatus,
	}

	if err.Any() {
		if err.IsUserError() {
			response["message"] = err.Text()

		} else if gin.Mode() != gin.ReleaseMode {
			response["debug_message"] = err.Text()
			delete(response, "message")
		}
	}

	this.GinContext.JSON(httpStatus, response)
}