admin: precise kind of error when filling claim

This commit is contained in:
nemunaire 2021-09-02 17:11:07 +02:00
parent 864f78e8fa
commit 2b58e707ca

View File

@ -80,16 +80,16 @@ func showClaim(claim fic.Claim, _ []byte) (interface{}, error) {
var e ClaimExported
var err error
if e.Team, err = claim.GetTeam(); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to find associated team: %w", err)
}
if e.Exercice, err = claim.GetExercice(); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to find associated exercice: %w", err)
}
if e.Assignee, err = claim.GetAssignee(); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to find associated assignee: %w", err)
}
if e.Descriptions, err = claim.GetDescriptions(); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to find claim's descriptions: %w", err)
}
e.LastUpdate = e.Creation
@ -118,7 +118,7 @@ type ClaimUploaded struct {
func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
var uc ClaimUploaded
if err := json.Unmarshal(body, &uc); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to decode JSON: %w", err)
}
if uc.Subject == "" {
@ -128,7 +128,7 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
var t *fic.Team
if uc.IdTeam != nil {
if team, err := fic.GetTeam(*uc.IdTeam); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to get associated team: %w", err)
} else {
t = &team
}
@ -139,7 +139,7 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
var e *fic.Exercice
if uc.IdExercice != nil {
if exercice, err := fic.GetExercice(*uc.IdExercice); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to get associated exercice: %w", err)
} else {
e = &exercice
}
@ -150,7 +150,7 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
var a *fic.ClaimAssignee
if uc.IdAssignee != nil {
if assignee, err := fic.GetAssignee(*uc.IdAssignee); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to get associated assignee: %w", err)
} else {
a = &assignee
}
@ -183,13 +183,13 @@ func generateTeamIssuesFile(team fic.Team) error {
func addClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
var ud fic.ClaimDescription
if err := json.Unmarshal(body, &ud); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to decode JSON: %w", err)
}
if assignee, err := fic.GetAssignee(ud.IdAssignee); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to get associated assignee: %w", err)
} else if description, err := claim.AddDescription(ud.Content, assignee, ud.Publish); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to add description: %w", err)
} else {
if team, _ := claim.GetTeam(); team != nil {
err = generateTeamIssuesFile(*team)
@ -202,11 +202,11 @@ func addClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
func updateClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
var ud fic.ClaimDescription
if err := json.Unmarshal(body, &ud); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to decode JSON: %w", err)
}
if _, err := ud.Update(); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to update description: %w", err)
} else {
if team, _ := claim.GetTeam(); team != nil {
err = generateTeamIssuesFile(*team)
@ -219,13 +219,13 @@ func updateClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
func updateClaim(claim fic.Claim, body []byte) (interface{}, error) {
var uc ClaimUploaded
if err := json.Unmarshal(body, &uc); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to decode JSON: %w", err)
}
uc.Id = claim.Id
if _, err := uc.Update(); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to update claim: %w", err)
} else {
if claim.State != uc.State {
if uc.Whoami != nil {
@ -275,7 +275,7 @@ func showClaimAssignee(assignee fic.ClaimAssignee, _ []byte) (interface{}, error
func newAssignee(_ httprouter.Params, body []byte) (interface{}, error) {
var ua fic.ClaimAssignee
if err := json.Unmarshal(body, &ua); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to decode JSON: %w", err)
}
return fic.NewClaimAssignee(ua.Name)
@ -284,13 +284,13 @@ func newAssignee(_ httprouter.Params, body []byte) (interface{}, error) {
func updateClaimAssignee(assignee fic.ClaimAssignee, body []byte) (interface{}, error) {
var ua fic.ClaimAssignee
if err := json.Unmarshal(body, &ua); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to decode JSON: %w", err)
}
ua.Id = assignee.Id
if _, err := ua.Update(); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to update claim assignee: %w", err)
} else {
return ua, nil
}