本文整理汇总了Golang中github.com/tsuru/tsuru/api/context.GetRequestError函数的典型用法代码示例。如果您正苦于以下问题:Golang GetRequestError函数的具体用法?Golang GetRequestError怎么用?Golang GetRequestError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetRequestError函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestAppLockMiddlewareOnLockedApp
func (s *S) TestAppLockMiddlewareOnLockedApp(c *check.C) {
oldDuration := lockWaitDuration
lockWaitDuration = 1 * time.Second
defer func() { lockWaitDuration = oldDuration }()
myApp := app.App{
Name: "my-app",
Lock: app.AppLock{
Locked: true,
Reason: "/app/my-app/deploy",
Owner: "someone",
AcquireDate: time.Date(2048, time.November, 10, 10, 0, 0, 0, time.UTC),
},
}
err := s.conn.Apps().Insert(myApp)
c.Assert(err, check.IsNil)
defer s.conn.Apps().Remove(bson.M{"name": myApp.Name})
recorder := httptest.NewRecorder()
request, err := http.NewRequest("POST", "/?:app=my-app", nil)
c.Assert(err, check.IsNil)
h, log := doHandler()
m := &appLockMiddleware{}
m.ServeHTTP(recorder, request, h)
c.Assert(log.called, check.Equals, false)
httpErr := context.GetRequestError(request).(*errors.HTTP)
c.Assert(httpErr.Code, check.Equals, http.StatusConflict)
c.Assert(httpErr.Message, check.Matches, "App locked by someone, running /app/my-app/deploy. Acquired in 2048-11-10.*")
}
开发者ID:keymon,项目名称:tsuru,代码行数:27,代码来源:middleware_test.go
示例2: TestAppLockMiddlewareReturns404IfNotApp
func (s *S) TestAppLockMiddlewareReturns404IfNotApp(c *check.C) {
recorder := httptest.NewRecorder()
request, err := http.NewRequest("POST", "/?:app=abc", nil)
c.Assert(err, check.IsNil)
h, log := doHandler()
m := &appLockMiddleware{}
m.ServeHTTP(recorder, request, h)
c.Assert(log.called, check.Equals, false)
httpErr := context.GetRequestError(request).(*errors.HTTP)
c.Assert(httpErr.Code, check.Equals, http.StatusNotFound)
c.Assert(httpErr.Message, check.Equals, "App not found.")
request, err = http.NewRequest("POST", "/?:appname=abc", nil)
c.Assert(err, check.IsNil)
m.ServeHTTP(recorder, request, h)
c.Assert(log.called, check.Equals, false)
httpErr = context.GetRequestError(request).(*errors.HTTP)
c.Assert(httpErr.Code, check.Equals, http.StatusNotFound)
c.Assert(httpErr.Message, check.Equals, "App not found.")
}
开发者ID:keymon,项目名称:tsuru,代码行数:19,代码来源:middleware_test.go
示例3: TestContextClearerMiddleware
func (s *S) TestContextClearerMiddleware(c *check.C) {
recorder := httptest.NewRecorder()
request, err := http.NewRequest("GET", "/", nil)
c.Assert(err, check.IsNil)
context.AddRequestError(request, fmt.Errorf("Some Error"))
h, log := doHandler()
contextClearerMiddleware(recorder, request, h)
c.Assert(log.called, check.Equals, true)
contErr := context.GetRequestError(request)
c.Assert(contErr, check.IsNil)
}
开发者ID:keymon,项目名称:tsuru,代码行数:11,代码来源:middleware_test.go
示例4: TestAuthTokenMiddlewareUserTokenAppNotFound
func (s *S) TestAuthTokenMiddlewareUserTokenAppNotFound(c *check.C) {
recorder := httptest.NewRecorder()
request, err := http.NewRequest("GET", "/?:app=something", nil)
c.Assert(err, check.IsNil)
request.Header.Set("Authorization", "bearer "+s.token.GetValue())
h, log := doHandler()
authTokenMiddleware(recorder, request, h)
c.Assert(log.called, check.Equals, false)
err = context.GetRequestError(request)
c.Assert(err, check.NotNil)
e, ok := err.(*errors.HTTP)
c.Assert(ok, check.Equals, true)
c.Assert(e.Code, check.Equals, http.StatusNotFound)
}
开发者ID:keymon,项目名称:tsuru,代码行数:14,代码来源:middleware_test.go
示例5: errorHandlingMiddleware
func errorHandlingMiddleware(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
next(w, r)
err := context.GetRequestError(r)
if err != nil {
code := http.StatusInternalServerError
if e, ok := err.(*errors.HTTP); ok {
code = e.Code
}
flushing, ok := w.(*io.FlushingWriter)
if ok && flushing.Wrote() {
fmt.Fprintln(w, err)
} else {
http.Error(w, err.Error(), code)
}
log.Errorf("failure running HTTP request %s %s (%d): %s", r.Method, r.URL.Path, code, err)
}
}
开发者ID:reoring,项目名称:tsuru,代码行数:17,代码来源:middleware.go
示例6: TestAuthTokenMiddlewareUserTokenNoAccessToTheApp
func (s *S) TestAuthTokenMiddlewareUserTokenNoAccessToTheApp(c *check.C) {
a := app.App{Name: "something"}
err := s.conn.Apps().Insert(a)
c.Assert(err, check.IsNil)
defer s.conn.Apps().Remove(bson.M{"name": a.Name})
recorder := httptest.NewRecorder()
request, err := http.NewRequest("GET", "/?:app=something", nil)
c.Assert(err, check.IsNil)
request.Header.Set("Authorization", "bearer "+s.token.GetValue())
h, log := doHandler()
authTokenMiddleware(recorder, request, h)
c.Assert(log.called, check.Equals, false)
err = context.GetRequestError(request)
c.Assert(err, check.NotNil)
e, ok := err.(*errors.HTTP)
c.Assert(ok, check.Equals, true)
c.Assert(e.Code, check.Equals, http.StatusForbidden)
}
开发者ID:keymon,项目名称:tsuru,代码行数:18,代码来源:middleware_test.go
示例7: TestAuthTokenMiddlewareWithIncorrectAppToken
func (s *S) TestAuthTokenMiddlewareWithIncorrectAppToken(c *check.C) {
token, err := nativeScheme.AppLogin("xyz")
c.Assert(err, check.IsNil)
defer s.conn.Tokens().Remove(bson.M{"token": token.GetValue()})
recorder := httptest.NewRecorder()
request, err := http.NewRequest("GET", "/?:app=abc", nil)
c.Assert(err, check.IsNil)
request.Header.Set("Authorization", "bearer "+token.GetValue())
h, log := doHandler()
authTokenMiddleware(recorder, request, h)
t := context.GetAuthToken(request)
c.Assert(t, check.IsNil)
c.Assert(log.called, check.Equals, false)
err = context.GetRequestError(request)
c.Assert(err, check.NotNil)
e, ok := err.(*errors.HTTP)
c.Assert(ok, check.Equals, true)
c.Assert(e.Code, check.Equals, http.StatusForbidden)
}
开发者ID:keymon,项目名称:tsuru,代码行数:19,代码来源:middleware_test.go
示例8: errorHandlingMiddleware
func errorHandlingMiddleware(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
next(w, r)
err := context.GetRequestError(r)
if err != nil {
code := http.StatusInternalServerError
if e, ok := err.(*tsuruErrors.HTTP); ok {
code = e.Code
}
flushing, ok := w.(*io.FlushingWriter)
if ok && flushing.Wrote() {
if w.Header().Get("Content-Type") == "application/x-json-stream" {
data, marshalErr := json.Marshal(io.SimpleJsonMessage{Error: err.Error()})
if marshalErr == nil {
w.Write(append(data, "\n"...))
}
} else {
fmt.Fprintln(w, err)
}
} else {
http.Error(w, err.Error(), code)
}
log.Errorf("failure running HTTP request %s %s (%d): %s", r.Method, r.URL.Path, code, err)
}
}
开发者ID:tsuru,项目名称:tsuru,代码行数:24,代码来源:middleware.go
注:本文中的github.com/tsuru/tsuru/api/context.GetRequestError函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论