@@ -2,6 +2,7 @@ package repository
22
33import (
44 "context"
5+ "fmt"
56 "shadmin/domain"
67 "shadmin/ent"
78 "shadmin/ent/dictitem"
@@ -309,16 +310,16 @@ func (dr *entDictRepository) DeleteType(ctx context.Context, id string) error {
309310
310311// 字典项相关实现
311312
312- func (dr * entDictRepository ) CreateItem (ctx context.Context , dictItem * domain.DictItem ) error {
313+ func (dr * entDictRepository ) CreateItem (ctx context.Context , dictItem * domain.DictItem ) ( err error ) {
313314 // 开启事务
314- tx , err := dr .client .Tx (ctx )
315- if err != nil {
316- return err
315+ tx , txErr := dr .client .Tx (ctx )
316+ if txErr != nil {
317+ return txErr
317318 }
318319 defer func () {
319320 if v := recover (); v != nil {
320321 _ = tx .Rollback ()
321- panic ( v )
322+ err = fmt . Errorf ( "panic recovered in CreateItem: %v" , v )
322323 }
323324 }()
324325
@@ -462,16 +463,16 @@ func (dr *entDictRepository) FetchItems(ctx context.Context, params domain.DictI
462463 return domain .NewPagedResult (result , total , params .Page , params .PageSize ), nil
463464}
464465
465- func (dr * entDictRepository ) UpdateItem (ctx context.Context , id string , updates domain.UpdateDictItemRequest ) error {
466+ func (dr * entDictRepository ) UpdateItem (ctx context.Context , id string , updates domain.UpdateDictItemRequest ) ( err error ) {
466467 // 开启事务
467- tx , err := dr .client .Tx (ctx )
468- if err != nil {
469- return err
468+ tx , txErr := dr .client .Tx (ctx )
469+ if txErr != nil {
470+ return txErr
470471 }
471472 defer func () {
472473 if v := recover (); v != nil {
473- tx .Rollback ()
474- panic ( v )
474+ _ = tx .Rollback ()
475+ err = fmt . Errorf ( "panic recovered in UpdateItem: %v" , v )
475476 }
476477 }()
477478
0 commit comments