Bläddra i källkod

first erro details replace message of error

EUGENIO SOUZA CARVALHO 4 år sedan
förälder
incheckning
1bb7d9fdf3
5 ändrade filer med 18 tillägg och 1 borttagningar
  1. 3 0
      api/errs/errs.go
  2. 1 0
      go.sum
  3. 7 0
      translate/got/functions.go
  4. 2 0
      translate/got/middleware_patch.go
  5. 5 1
      translate/got/middleware_post.go

+ 3 - 0
api/errs/errs.go

@@ -45,6 +45,9 @@ func RegisterMapErrorFunction(id string, fn ErrorMapFunction) {
 
 func (e *Error) Details(desc *Detail) *Error {
 	e.Errors = append(e.Errors, desc)
+	if len(e.Errors) == 1 {
+		e.Message = desc.Message
+	}
 	return e
 }
 

+ 1 - 0
go.sum

@@ -175,6 +175,7 @@ golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20190327201419-c70d86f8b7cf h1:++r/Kj1CfG42p6XntDItK1TfB5V6Vq/baDeKvV1q5gY=
 golang.org/x/tools v0.0.0-20190327201419-c70d86f8b7cf/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE=

+ 7 - 0
translate/got/functions.go

@@ -71,3 +71,10 @@ func parseMethodActions(actions []Action) string {
 
 	return strings.Join(actionsCallStmt, ",\n")
 }
+
+func getCustom(options map[string]interface{}, path string) (resp interface{}) {
+	if options != nil {
+		resp = options[path]
+	}
+	return
+}

+ 2 - 0
translate/got/middleware_patch.go

@@ -32,6 +32,7 @@ func init() {
 	user := values.Get("$user.ref").(*models.UserReference)
 	entity.UpdatedBy = user
 	values.Set("entity", entity)
+	{{if .entityAlias }} values.Set("{{.entityAlias}}", entity) {{end}}
 	
 	{{if .preconditions}}
 		if _, err = executeAction(
@@ -118,6 +119,7 @@ var (
 					"hasUpdateRelation": SR.Has(method.Entity),
 					"preconditions":     parseMethodActions(method.Preconditions),
 					"beforeResponse":    parseMethodActions(method.BeforeResponse),
+					"entityAlias":       getCustom(method.Custom, "go.entity.alias"),
 				}
 			)
 

+ 5 - 1
translate/got/middleware_post.go

@@ -32,7 +32,9 @@ func init() {
 	entity.SetMode("create")
 
 	values.Set("entity", entity)
-	
+
+	{{if .entityAlias }} values.Set("{{.entityAlias}}", entity) {{end}}
+
 	if err = api.Validate(entity); err != nil {
 		return
 	}
@@ -79,6 +81,7 @@ var (
 		Id:   "post",
 		Type: "method",
 		Fn: func(ctx *MiddlewareContext) error {
+
 			var (
 				project          = ctx.Project
 				method           = ctx.Method
@@ -97,6 +100,7 @@ var (
 					"methodName":       strings.Title(method.ID),
 					"preconditions":    parseMethodActions(method.Preconditions),
 					"beforeResponse":   parseMethodActions(method.BeforeResponse),
+					"entityAlias":      getCustom(method.Custom, "go.entity.alias"),
 				}
 			)
 			// Nome do metodo que verifica se a entidade tem dependencias