本文整理汇总了Golang中github.com/almighty/almighty-core/jsonapi.ErrorToJSONAPIErrors函数的典型用法代码示例。如果您正苦于以下问题:Golang ErrorToJSONAPIErrors函数的具体用法?Golang ErrorToJSONAPIErrors怎么用?Golang ErrorToJSONAPIErrors使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ErrorToJSONAPIErrors函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Show
// Show returns the authorized user based on the provided Token
func (c *UserController) Show(ctx *app.ShowUserContext) error {
id, err := c.tokenManager.Locate(ctx)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(err.Error()))
return ctx.BadRequest(jerrors)
}
return application.Transactional(c.db, func(appl application.Application) error {
identity, err := appl.Identities().Load(ctx, id)
if err != nil || identity == nil {
log.Error(ctx, map[string]interface{}{
"identityID": id,
}, "auth token containers id %s of unknown Identity", id)
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrUnauthorized(fmt.Sprintf("Auth token contains id %s of unknown Identity\n", id)))
return ctx.Unauthorized(jerrors)
}
var user *account.User
userID := identity.UserID
if userID.Valid {
user, err = appl.Users().Load(ctx.Context, userID.UUID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, errors.Wrap(err, fmt.Sprintf("Can't load user with id %s", userID.UUID)))
}
}
return ctx.OK(ConvertUser(ctx.RequestData, identity, user))
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:30,代码来源:user.go
示例2: createWorkItemLink
func createWorkItemLink(ctx *workItemLinkContext, funcs createWorkItemLinkFuncs, payload *app.CreateWorkItemLinkPayload) error {
// Convert payload from app to model representation
model := link.WorkItemLink{}
in := app.WorkItemLinkSingle{
Data: payload.Data,
}
err := link.ConvertLinkToModel(in, &model)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(err)
return funcs.BadRequest(jerrors)
}
link, err := ctx.Application.WorkItemLinks().Create(ctx.Context, model.SourceID, model.TargetID, model.LinkTypeID)
if err != nil {
cause := errs.Cause(err)
switch cause.(type) {
case errors.NotFoundError:
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(err.Error()))
return funcs.BadRequest(jerrors)
case errors.BadParameterError:
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(err.Error()))
return funcs.BadRequest(jerrors)
default:
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
}
if err := enrichLinkSingle(ctx, link); err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
ctx.ResponseData.Header().Set("Location", app.WorkItemLinkHref(link.Data.ID))
return funcs.Created(link)
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:34,代码来源:work-item-link.go
示例3: Update
// Update runs the update action.
func (c *TrackerqueryController) Update(ctx *app.UpdateTrackerqueryContext) error {
result := application.Transactional(c.db, func(appl application.Application) error {
toSave := app.TrackerQuery{
ID: ctx.ID,
Query: ctx.Payload.Query,
Schedule: ctx.Payload.Schedule,
TrackerID: ctx.Payload.TrackerID,
}
tq, err := appl.TrackerQueries().Save(ctx.Context, toSave)
if err != nil {
cause := errs.Cause(err)
switch cause.(type) {
case remoteworkitem.BadParameterError, remoteworkitem.ConversionError:
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(err.Error()))
return ctx.BadRequest(jerrors)
default:
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal(err.Error()))
return ctx.InternalServerError(jerrors)
}
}
return ctx.OK(tq)
})
c.scheduler.ScheduleAllQueries()
return result
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:28,代码来源:trackerquery.go
示例4: Create
// Create runs the create action.
func (c *WorkItemRelationshipsLinksController) Create(ctx *app.CreateWorkItemRelationshipsLinksContext) error {
return application.Transactional(c.db, func(appl application.Application) error {
// Check that current work item does indeed exist
if _, err := appl.WorkItems().Load(ctx.Context, ctx.ID); err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
// Check that the source ID of the link is the same as the current work
// item ID.
src, _ := getSrcTgt(ctx.Payload.Data)
if src != nil && *src != ctx.ID {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(fmt.Sprintf("data.relationships.source.data.id is \"%s\" but must be \"%s\"", ctx.Payload.Data.Relationships.Source.Data.ID, ctx.ID)))
return ctx.BadRequest(jerrors)
}
// If no source is specified we pre-fill the source field of the payload
// with the current work item ID from the URL. This is for convenience.
if src == nil {
if ctx.Payload.Data.Relationships == nil {
ctx.Payload.Data.Relationships = &app.WorkItemLinkRelationships{}
}
if ctx.Payload.Data.Relationships.Source == nil {
ctx.Payload.Data.Relationships.Source = &app.RelationWorkItem{}
}
if ctx.Payload.Data.Relationships.Source.Data == nil {
ctx.Payload.Data.Relationships.Source.Data = &app.RelationWorkItemData{}
}
ctx.Payload.Data.Relationships.Source.Data.ID = ctx.ID
ctx.Payload.Data.Relationships.Source.Data.Type = link.EndpointWorkItems
}
return createWorkItemLink(newWorkItemLinkContext(ctx.Context, appl, c.db, ctx.RequestData, ctx.ResponseData, app.WorkItemLinkHref), ctx, ctx.Payload)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:33,代码来源:work-item-relationships-links.go
示例5: Create
// Create runs the create action.
func (c *WorkItemLinkTypeController) Create(ctx *app.CreateWorkItemLinkTypeContext) error {
// WorkItemLinkTypeController_Create: start_implement
// Convert payload from app to model representation
model := link.WorkItemLinkType{}
in := app.WorkItemLinkTypeSingle{
Data: ctx.Payload.Data,
}
err := link.ConvertLinkTypeToModel(in, &model)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(err.Error()))
return ctx.BadRequest(jerrors)
}
return application.Transactional(c.db, func(appl application.Application) error {
linkType, err := appl.WorkItemLinkTypes().Create(ctx.Context, model.Name, model.Description, model.SourceTypeName, model.TargetTypeName, model.ForwardName, model.ReverseName, model.Topology, model.LinkCategoryID)
if err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
// Enrich
linkCtx := newWorkItemLinkContext(ctx.Context, appl, c.db, ctx.RequestData, ctx.ResponseData, app.WorkItemLinkTypeHref)
err = enrichLinkTypeSingle(linkCtx, linkType)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal("Failed to enrich link type: %s", err.Error()))
return ctx.InternalServerError(jerrors)
}
ctx.ResponseData.Header().Set("Location", app.WorkItemLinkTypeHref(linkType.Data.ID))
return ctx.Created(linkType)
})
// WorkItemLinkTypeController_Create: end_implement
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:31,代码来源:work-item-link-type.go
示例6: showWorkItemLink
func showWorkItemLink(ctx *workItemLinkContext, funcs showWorkItemLinkFuncs, linkID string) error {
link, err := ctx.Application.WorkItemLinks().Load(ctx.Context, linkID)
if err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
if err := enrichLinkSingle(ctx, link); err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
return funcs.OK(link)
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:12,代码来源:work-item-link.go
示例7: updateWorkItemLink
func updateWorkItemLink(ctx *workItemLinkContext, funcs updateWorkItemLinkFuncs, payload *app.UpdateWorkItemLinkPayload) error {
toSave := app.WorkItemLinkSingle{
Data: payload.Data,
}
link, err := ctx.Application.WorkItemLinks().Save(ctx.Context, toSave)
if err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
if err := enrichLinkSingle(ctx, link); err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
return funcs.OK(link)
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:15,代码来源:work-item-link.go
示例8: List
// List runs the list action
func (c *WorkitemtypeController) List(ctx *app.ListWorkitemtypeContext) error {
start, limit, err := parseLimit(ctx.Page)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(fmt.Sprintf("could not parse paging: %s", err.Error())))
return ctx.BadRequest(jerrors)
}
return application.Transactional(c.db, func(appl application.Application) error {
result, err := appl.WorkItemTypes().List(ctx.Context, start, &limit)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(fmt.Sprintf("Error listing work item types: %s", err.Error())))
return ctx.BadRequest(jerrors)
}
return ctx.OK(result)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:16,代码来源:workitemtype.go
示例9: Show
// Show runs the show action.
func (c *WorkItemLinkCategoryController) Show(ctx *app.ShowWorkItemLinkCategoryContext) error {
return application.Transactional(c.db, func(appl application.Application) error {
res, err := appl.WorkItemLinkCategories().Load(ctx.Context, ctx.ID)
if err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
linkCtx := newWorkItemLinkContext(ctx.Context, appl, c.db, ctx.RequestData, ctx.ResponseData, app.WorkItemLinkCategoryHref)
err = enrichLinkCategorySingle(linkCtx, res)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal("Failed to enrich link category: %s", err.Error()))
return ctx.InternalServerError(jerrors)
}
return ctx.OK(res)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:17,代码来源:work-item-link-category.go
示例10: deleteWorkItemLink
func deleteWorkItemLink(ctx *workItemLinkContext, funcs deleteWorkItemLinkFuncs, linkID string) error {
err := ctx.Application.WorkItemLinks().Delete(ctx.Context, linkID)
if err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
return funcs.OK([]byte{})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:8,代码来源:work-item-link.go
示例11: Create
// Create runs the create action.
func (c *WorkItemLinkCategoryController) Create(ctx *app.CreateWorkItemLinkCategoryContext) error {
return application.Transactional(c.db, func(appl application.Application) error {
cat, err := appl.WorkItemLinkCategories().Create(ctx.Context, ctx.Payload.Data.Attributes.Name, ctx.Payload.Data.Attributes.Description)
if err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
linkCtx := newWorkItemLinkContext(ctx.Context, appl, c.db, ctx.RequestData, ctx.ResponseData, app.WorkItemLinkCategoryHref)
err = enrichLinkCategorySingle(linkCtx, cat)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal("Failed to enrich link category: %s", err.Error()))
return ctx.InternalServerError(jerrors)
}
ctx.ResponseData.Header().Set("Location", app.WorkItemLinkCategoryHref(cat.Data.ID))
return ctx.Created(cat)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:18,代码来源:work-item-link-category.go
示例12: Show
// Show runs the show action.
func (c *SearchController) Show(ctx *app.ShowSearchContext) error {
var offset int
var limit int
offset, limit = computePagingLimts(ctx.PageOffset, ctx.PageLimit)
// ToDo : Keep URL registeration central somehow.
hostString := ctx.RequestData.Host
if hostString == "" {
hostString = configuration.GetHTTPAddress()
}
urlRegexString := fmt.Sprintf("(?P<domain>%s)(?P<path>/work-item/list/detail/)(?P<id>\\d*)", hostString)
search.RegisterAsKnownURL(search.HostRegistrationKeyForListWI, urlRegexString)
urlRegexString = fmt.Sprintf("(?P<domain>%s)(?P<path>/work-item/board/detail/)(?P<id>\\d*)", hostString)
search.RegisterAsKnownURL(search.HostRegistrationKeyForBoardWI, urlRegexString)
return application.Transactional(c.db, func(appl application.Application) error {
//return transaction.Do(c.ts, func() error {
result, c, err := appl.SearchItems().SearchFullText(ctx.Context, ctx.Q, &offset, &limit)
count := int(c)
if err != nil {
cause := errs.Cause(err)
switch cause.(type) {
case errors.BadParameterError:
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(fmt.Sprintf("Error listing work items: %s", err.Error())))
return ctx.BadRequest(jerrors)
default:
log.Error(ctx, map[string]interface{}{
"err": err,
}, "unable to list the work items")
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal(err.Error()))
return ctx.InternalServerError(jerrors)
}
}
response := app.SearchWorkItemList{
Links: &app.PagingLinks{},
Meta: &app.WorkItemListResponseMeta{TotalCount: count},
Data: ConvertWorkItems(ctx.RequestData, result),
}
setPagingLinks(response.Links, buildAbsoluteURL(ctx.RequestData), len(result), offset, limit, count, "q="+ctx.Q)
return ctx.OK(&response)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:46,代码来源:search.go
示例13: listWorkItemLink
func listWorkItemLink(ctx *workItemLinkContext, funcs listWorkItemLinkFuncs, wiIDStr *string) error {
var linkArr *app.WorkItemLinkList
var err error
if wiIDStr != nil {
linkArr, err = ctx.Application.WorkItemLinks().ListByWorkItemID(ctx.Context, *wiIDStr)
} else {
linkArr, err = ctx.Application.WorkItemLinks().List(ctx.Context)
}
if err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
if err := enrichLinkList(ctx, linkArr); err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
return funcs.OK(linkArr)
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:19,代码来源:work-item-link.go
示例14: List
// List runs the list action.
func (c *WorkItemLinkTypeController) List(ctx *app.ListWorkItemLinkTypeContext) error {
// WorkItemLinkTypeController_List: start_implement
return application.Transactional(c.db, func(appl application.Application) error {
result, err := appl.WorkItemLinkTypes().List(ctx.Context)
if err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
// Enrich
linkCtx := newWorkItemLinkContext(ctx.Context, appl, c.db, ctx.RequestData, ctx.ResponseData, app.WorkItemLinkTypeHref)
err = enrichLinkTypeList(linkCtx, result)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal("Failed to enrich link types: %s", err.Error()))
return ctx.InternalServerError(jerrors)
}
return ctx.OK(result)
})
// WorkItemLinkTypeController_List: end_implement
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:20,代码来源:work-item-link-type.go
示例15: Delete
// Delete runs the delete action.
func (c *WorkItemLinkCategoryController) Delete(ctx *app.DeleteWorkItemLinkCategoryContext) error {
return application.Transactional(c.db, func(appl application.Application) error {
err := appl.WorkItemLinkCategories().Delete(ctx.Context, ctx.ID)
if err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
return ctx.OK([]byte{})
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:11,代码来源:work-item-link-category.go
示例16: Delete
// Delete runs the delete action.
func (c *TrackerqueryController) Delete(ctx *app.DeleteTrackerqueryContext) error {
result := application.Transactional(c.db, func(appl application.Application) error {
err := appl.TrackerQueries().Delete(ctx.Context, ctx.ID)
if err != nil {
cause := errs.Cause(err)
switch cause.(type) {
case remoteworkitem.NotFoundError:
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrNotFound(err.Error()))
return ctx.NotFound(jerrors)
default:
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal(err.Error()))
return ctx.InternalServerError(jerrors)
}
}
return ctx.OK([]byte{})
})
c.scheduler.ScheduleAllQueries()
return result
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:20,代码来源:trackerquery.go
示例17: List
// List runs the list action.
func (c *IdentityController) List(ctx *app.ListIdentityContext) error {
return application.Transactional(c.db, func(appl application.Application) error {
result, err := appl.Identities().List(ctx.Context)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal(fmt.Sprintf("Error listing identities: %s", err.Error())))
return ctx.InternalServerError(jerrors)
}
return ctx.OK(result)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:11,代码来源:identity.go
示例18: Update
// Update runs the update action.
func (c *WorkItemLinkCategoryController) Update(ctx *app.UpdateWorkItemLinkCategoryContext) error {
return application.Transactional(c.db, func(appl application.Application) error {
toSave := app.WorkItemLinkCategorySingle{
Data: ctx.Payload.Data,
}
linkCategory, err := appl.WorkItemLinkCategories().Save(ctx.Context, toSave)
if err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
// Enrich
linkCtx := newWorkItemLinkContext(ctx.Context, appl, c.db, ctx.RequestData, ctx.ResponseData, app.WorkItemLinkCategoryHref)
err = enrichLinkCategorySingle(linkCtx, linkCategory)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal("Failed to enrich link category: %s", err.Error()))
return ctx.InternalServerError(jerrors)
}
return ctx.OK(linkCategory)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:21,代码来源:work-item-link-category.go
示例19: Create
// Create runs the create action.
func (c *TrackerqueryController) Create(ctx *app.CreateTrackerqueryContext) error {
result := application.Transactional(c.db, func(appl application.Application) error {
tq, err := appl.TrackerQueries().Create(ctx.Context, ctx.Payload.Query, ctx.Payload.Schedule, ctx.Payload.TrackerID)
if err != nil {
cause := errs.Cause(err)
switch cause.(type) {
case remoteworkitem.BadParameterError, remoteworkitem.ConversionError:
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(err.Error()))
return ctx.BadRequest(jerrors)
default:
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal(err.Error()))
return ctx.InternalServerError(jerrors)
}
}
ctx.ResponseData.Header().Set("Location", app.TrackerqueryHref(tq.ID))
return ctx.Created(tq)
})
c.scheduler.ScheduleAllQueries()
return result
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:21,代码来源:trackerquery.go
示例20: Show
// Show runs the show action.
func (c *TrackerController) Show(ctx *app.ShowTrackerContext) error {
return application.Transactional(c.db, func(appl application.Application) error {
t, err := appl.Trackers().Load(ctx.Context, ctx.ID)
if err != nil {
cause := errs.Cause(err)
switch cause.(type) {
case remoteworkitem.NotFoundError:
log.Error(ctx, map[string]interface{}{
"trackerID": ctx.ID,
}, "tracker controller not found")
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrNotFound(err.Error()))
return ctx.NotFound(jerrors)
default:
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal(err.Error()))
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
}
return ctx.OK(t)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:21,代码来源:tracker.go
注:本文中的github.com/almighty/almighty-core/jsonapi.ErrorToJSONAPIErrors函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论