예제 #1
0
파일: main.go 프로젝트: twanies/gonzo
// errorHandler will catch all errors returned from handlers and convert them
// into a JSON response. If the error is not from the type HTTPError an internal
// server error will follow.
func errorHandler(err error, c *echo.Context) {
	if httpError, ok := err.(handler.HTTPError); ok {
		c.JSON(httpError.Code, httpError)
		return
	}
	c.Error(errors.New("internal server error"))
}
예제 #2
0
파일: dashboard.go 프로젝트: jwulf/zedlist
// JobsNewPost process the new job form.
//
//		Method           POST
//
//		Route            /dash/jobs/new
//
//		Restrictions     Yes
//
// 		Template         None
func JobsNewPost(ctx *echo.Context) error {
	var flashMessages = flash.New()
	f := forms.New(utils.GetLang(ctx))
	jf := f.JobForm()(ctx.Request())
	if !jf.IsValid() {
		// TODO: improve flash message ?
		flashMessages.Err(msgInvalidorm)
		flashMessages.Save(ctx)
		ctx.Redirect(http.StatusFound, "/dash/jobs/new")
		return nil
	}

	if isLoged := ctx.Get("IsLoged"); isLoged != nil {
		person := ctx.Get("User").(*models.Person)
		if jerr := query.PersonCreateJob(person, jf.GetModel().(forms.JobForm)); jerr != nil {
			// TODO: improve flash message ?
			flashMessages.Err("some really bad fish happened")
			flashMessages.Save(ctx)
			ctx.Redirect(http.StatusFound, "/dash/jobs/new")
			return nil
		}
		// add flash message
		flashMessages.Success("new job was created successful")
		flashMessages.Save(ctx)

		ctx.Redirect(http.StatusFound, "/dash/")
		return nil
	}
	he := echo.NewHTTPError(http.StatusUnauthorized)
	ctx.Error(he)
	return nil
}
예제 #3
0
// shortcut to get session
func Default(c echo.Context) Session {
	ses, ok := c.Get(DefaultKey).(Session)
	if !ok {
		c.Error(ErrDefaultSessionMiddlewareNotRegistered)
	}
	return ses
}