Skip to content

Commit 23fda22

Browse files
committed
Wrap errors inside of err!= nil
1 parent 223f649 commit 23fda22

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

coderd/templateversions.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,14 @@ func (api *API) previousTemplateVersionByOrganizationAndName(rw http.ResponseWri
648648
OrganizationID: organization.ID,
649649
Name: templateVersionName,
650650
})
651-
if errors.Is(err, sql.ErrNoRows) {
652-
httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
653-
Message: fmt.Sprintf("No template version found by name %q.", templateVersionName),
654-
})
655-
return
656-
}
657651
if err != nil {
652+
if errors.Is(err, sql.ErrNoRows) {
653+
httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
654+
Message: fmt.Sprintf("No template version found by name %q.", templateVersionName),
655+
})
656+
return
657+
}
658+
658659
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
659660
Message: "Internal error fetching template version.",
660661
Detail: err.Error(),
@@ -667,13 +668,15 @@ func (api *API) previousTemplateVersionByOrganizationAndName(rw http.ResponseWri
667668
Name: templateVersionName,
668669
TemplateID: templateVersion.TemplateID,
669670
})
670-
if errors.Is(err, sql.ErrNoRows) {
671-
httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
672-
Message: fmt.Sprintf("No previous template version found for %q.", templateVersionName),
673-
})
674-
return
675-
}
671+
676672
if err != nil {
673+
if errors.Is(err, sql.ErrNoRows) {
674+
httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
675+
Message: fmt.Sprintf("No previous template version found for %q.", templateVersionName),
676+
})
677+
return
678+
}
679+
677680
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
678681
Message: "Internal error fetching the previous template version.",
679682
Detail: err.Error(),

0 commit comments

Comments
 (0)