Skip to content

Commit 7cff679

Browse files
fix: 500 fixes second iteration (#4464)
* FetchChartNotes return 4xx when installed app or installed app versions not found * GetDeploymentHistory and GetInstalledAppVersion to return 4xx when installed app or installed app versions not found * fixes * adding pg:",discard_unknown_columns" in tables where doesn't exist * fix for Git Sensor response * fix for inception * fix for k8s resource delete * fix for pipeline already exists * fix for pipeline already exists * fix * fix * fix * fix * go mod version changes * merged * common lib main version sync * main merge --------- Co-authored-by: ShashwatDadhich <[email protected]>
1 parent 897ffda commit 7cff679

File tree

14 files changed

+33
-13
lines changed

14 files changed

+33
-13
lines changed

api/appStore/deployment/CommonDeploymentRestHandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (handler *CommonDeploymentRestHandlerImpl) getAppOfferingMode(installedAppI
9393
}
9494
installedAppDto, err = handler.appStoreDeploymentServiceC.GetInstalledAppByClusterNamespaceAndName(appIdentifier.ClusterId, appIdentifier.Namespace, appIdentifier.ReleaseName)
9595
if err != nil {
96-
err = &util.ApiError{HttpStatusCode: http.StatusInternalServerError, UserMessage: "unable to find app in database"}
96+
err = &util.ApiError{HttpStatusCode: http.StatusBadRequest, UserMessage: "unable to find app in database"}
9797
return appOfferingMode, installedAppDto, err
9898
}
9999
// this is the case when hyperion apps does not linked yet
@@ -119,7 +119,7 @@ func (handler *CommonDeploymentRestHandlerImpl) getAppOfferingMode(installedAppI
119119
}
120120
installedAppDto, err = handler.appStoreDeploymentServiceC.GetInstalledAppByInstalledAppId(installedAppId)
121121
if err != nil {
122-
err = &util.ApiError{HttpStatusCode: http.StatusInternalServerError, UserMessage: "unable to find app in database"}
122+
err = &util.ApiError{HttpStatusCode: http.StatusBadRequest, UserMessage: "unable to find app in database"}
123123
return appOfferingMode, installedAppDto, err
124124
}
125125
} else {

api/k8s/application/k8sApplicationRestHandler.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"github.com/devtron-labs/common-lib/utils"
89
"net/http"
910
"strconv"
1011
"strings"
@@ -512,8 +513,17 @@ func (handler *K8sApplicationRestHandlerImpl) DeleteResource(w http.ResponseWrit
512513

513514
resource, err := handler.k8sApplicationService.DeleteResourceWithAudit(r.Context(), &request, userId)
514515
if err != nil {
516+
errCode := http.StatusInternalServerError
517+
if apiErr, ok := err.(*utils.ApiError); ok {
518+
errCode = apiErr.HttpStatusCode
519+
switch errCode {
520+
case http.StatusNotFound:
521+
errorMessage := "resource not found"
522+
err = fmt.Errorf("%s: %w", errorMessage, err)
523+
}
524+
}
515525
handler.logger.Errorw("error in deleting resource", "err", err)
516-
common.WriteJsonResp(w, err, resource, http.StatusInternalServerError)
526+
common.WriteJsonResp(w, err, resource, errCode)
517527
return
518528
}
519529
common.WriteJsonResp(w, nil, resource, http.StatusOK)

client/gitSensor/GitSensorGrpcClient.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,12 @@ func (client *GrpcApiClientImpl) GetCommitMetadataForPipelineMaterial(ctx contex
335335
GitTag: req.GitTag,
336336
BranchName: req.BranchName,
337337
})
338+
338339
if err != nil {
339340
return nil, err
340341
}
341-
if res == nil {
342+
343+
if res.Commit == "" {
342344
return nil, nil
343345
}
344346

internal/sql/repository/NotificationSettingsRepository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type NotificationSettingsViewWithAppEnv struct {
7373
}
7474

7575
type NotificationSettings struct {
76-
tableName struct{} `sql:"notification_settings"`
76+
tableName struct{} `sql:"notification_settings" pg:",discard_unknown_columns"`
7777
Id int `sql:"id,pk"`
7878
TeamId *int `sql:"team_id"`
7979
AppId *int `sql:"app_id"`

internal/sql/repository/WebhookEventDataRepository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
type WebhookEventData struct {
25-
tableName struct{} `sql:"webhook_event_data"`
25+
tableName struct{} `sql:"webhook_event_data" pg:",discard_unknown_columns"`
2626
Id int `sql:"id,pk"`
2727
GitHostId int `sql:"git_host_id,notnull"`
2828
EventType string `sql:"event_type,notnull"`

pkg/appStore/deployment/service/AppStoreDeploymentService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ func (impl AppStoreDeploymentServiceImpl) GetInstalledAppVersion(id int, userId
15661566
app, err := impl.installedAppRepository.GetInstalledAppVersion(id)
15671567
if err != nil {
15681568
if err == pg.ErrNoRows {
1569-
return nil, fmt.Errorf("values are outdated. please fetch the latest version and try again")
1569+
return nil, &util.ApiError{HttpStatusCode: http.StatusBadRequest, Code: "400", UserMessage: "values are outdated. please fetch the latest version and try again", InternalMessage: err.Error()}
15701570
}
15711571
impl.logger.Errorw("error while fetching from db", "error", err)
15721572
return nil, err

pkg/appStore/deployment/service/InstalledAppService.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,11 +919,14 @@ func (impl *InstalledAppServiceImpl) FetchChartNotes(installedAppId int, envId i
919919
installedApp, err := impl.installedAppRepository.FetchNotes(installedAppId)
920920
if err != nil && err != pg.ErrNoRows {
921921
return "", err
922+
} else if err == pg.ErrNoRows {
923+
impl.logger.Errorw("installed app not found or may have been deleted", "installedAppId", installedAppId, "envId", envId)
924+
return "", &util.ApiError{HttpStatusCode: http.StatusBadRequest, Code: "400", UserMessage: "Installed app not found in database or may have been deleted", InternalMessage: err.Error()}
922925
}
923926
installedAppVerison, err := impl.installedAppRepository.GetInstalledAppVersionByInstalledAppIdAndEnvId(installedAppId, envId)
924927
if err != nil {
925928
if err == pg.ErrNoRows {
926-
return "", fmt.Errorf("values are outdated. please fetch the latest version and try again")
929+
return "", &util.ApiError{HttpStatusCode: http.StatusBadRequest, Code: "400", UserMessage: "values are outdated. please fetch the latest version and try again", InternalMessage: err.Error()}
927930
}
928931
impl.logger.Errorw("error fetching installed app version in installed app service", "err", err)
929932
return "", err

pkg/appStore/deployment/tool/gitops/AppStoreDeploymentArgoCdService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ func (impl AppStoreDeploymentArgoCdServiceImpl) GetDeploymentHistory(ctx context
463463
installedAppVersions, err := impl.installedAppRepository.GetInstalledAppVersionByInstalledAppIdMeta(installedAppDto.InstalledAppId)
464464
if err != nil {
465465
if err == pg.ErrNoRows {
466-
return nil, fmt.Errorf("values are outdated. please fetch the latest version and try again")
466+
return nil, &util.ApiError{HttpStatusCode: http.StatusBadRequest, Code: "400", UserMessage: "values are outdated. please fetch the latest version and try again", InternalMessage: err.Error()}
467467
}
468468
impl.Logger.Errorw("error while fetching installed version", "error", err)
469469
return result, err

pkg/chartRepo/repository/ChartRepoRepository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type ChartRepoFields struct {
4040
AllowInsecureConnection bool `sql:"allow_insecure_connection"`
4141
}
4242
type ChartRepo struct {
43-
tableName struct{} `sql:"chart_repo"`
43+
tableName struct{} `sql:"chart_repo" pg:",discard_unknown_columns"`
4444
ChartRepoFields
4545
sql.AuditLog
4646
}

pkg/externalLink/ExternalLinkIdentifierMappingRepository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
)
2626

2727
type ExternalLinkIdentifierMapping struct {
28-
tableName struct{} `sql:"external_link_identifier_mapping"`
28+
tableName struct{} `sql:"external_link_identifier_mapping" pg:",discard_unknown_columns"`
2929
Id int `sql:"id,pk"`
3030
ExternalLinkId int `sql:"external_link_id,notnull"`
3131
Type AppIdentifier `sql:"type,notnull"`

0 commit comments

Comments
 (0)