Skip to content

Commit

Permalink
Error codes adjusted.
Browse files Browse the repository at this point in the history
  • Loading branch information
grealyve committed Mar 11, 2024
1 parent 56c1309 commit a0784d7
Show file tree
Hide file tree
Showing 6 changed files with 1,713 additions and 432 deletions.
10 changes: 5 additions & 5 deletions controller/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func CheckActivities(ctx *gin.Context) {
helpers.SendMessageWS("Activities", "chista_EXIT_chista", "info")
default:
helpers.SendMessageWS("Activities", "Invalid query string or parameter.", "error")
ctx.JSON(400, gin.H{"Error": "Invalid Request, you have to pass a valid parameter and argument."})
ctx.JSON(http.StatusBadRequest, gin.H{"Error": "Invalid Request, you have to pass a valid parameter and argument."})
helpers.SendMessageWS("Activities", "chista_EXIT_chista", "info")
}

Expand Down Expand Up @@ -116,7 +116,7 @@ func checkRansom(ransomNames []string, ctx *gin.Context) {
if len(filteredData) == 0 {
logger.Log.Debugln("Requested data could not found.")
helpers.SendMessageWS("Activities", "Requested data could not found.", "info")
ctx.JSON(http.StatusNotFound, gin.H{"Message": "Requested data could not found."})
ctx.JSON(http.StatusBadRequest, gin.H{"Message": "Requested data could not found."})
helpers.SendMessageWS("Activities", "chista_EXIT_chista", "info")
return
}
Expand Down Expand Up @@ -184,7 +184,7 @@ func openAndPutintoModel(ctx *gin.Context) []models.RansomActivityData {
file, err := os.Open(ransomDataPath)
if err != nil {
logger.Log.Debugf("Error opening %s %v\n", ransomDataPath, err)
ctx.JSON(http.StatusNotFound, gin.H{"error": "Error opening activitiesRansomData.json"})
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "Error opening activitiesRansomData.json"})
helpers.SendMessageWS("Activities", fmt.Sprintf("Error opening %s %v\n", ransomDataPath, err), "error")
}
defer file.Close()
Expand All @@ -194,15 +194,15 @@ func openAndPutintoModel(ctx *gin.Context) []models.RansomActivityData {
data, err := io.ReadAll(file)
if err != nil {
logger.Log.Errorf("Error reading %s %v\n", ransomDataPath, err)
ctx.JSON(http.StatusNotFound, gin.H{"error": "File can't be read"})
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "File can't be read"})
helpers.SendMessageWS("Activities", fmt.Sprintf("Error reading %s: %v", ransomDataPath, err), "error")
}

// Unmarshalling the data.
var jsonData []models.RansomActivityData
if err := json.Unmarshal(data, &jsonData); err != nil {
logger.Log.Errorf("Error during unmarshal data: %v\n", err)
ctx.JSON(http.StatusNotFound, gin.H{"error": "Error unmarshaling data."})
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "Error unmarshaling data."})
helpers.SendMessageWS("Activities", fmt.Sprintf("Error unmarshaling ransom data: %v", err), "error")
}

Expand Down
2 changes: 1 addition & 1 deletion controller/blacklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func CheckBlacklist(ctx *gin.Context) {
helpers.VERBOSITY = verbosity

// Creattes context for http request.
timeoutContext, timeoutCancel := context.WithTimeout(context.Background(), 45*time.Second)
timeoutContext, timeoutCancel := context.WithTimeout(context.Background(), 30*time.Second)
defer timeoutCancel()

chromedpContext, chromedpCancel := chromedp.NewContext(timeoutContext)
Expand Down
8 changes: 4 additions & 4 deletions controller/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func GetSources(ctx *gin.Context) {
ctx.JSON(http.StatusInternalServerError, gin.H{"msg": "Cannot initilaize WebSocket connection with Client. If you want to use just HTTP API set API_ONLY=true"})
return
}
time.Sleep(3 * time.Second)
time.Sleep(2 * time.Second)
defer helpers.CloseWSConnection()

// Checking the verbosity condition.
Expand Down Expand Up @@ -85,7 +85,7 @@ func GetCTIData(urls string, ctx *gin.Context) {
if !strings.Contains(arg, "=") {
logger.Log.Errorln("Please pass a argument to parameter. Usage should be like this: `/api/v1/source?src=forum=your_parameter,market=your_parameter`")
helpers.SendMessageWS("Source", "Please pass a argument to parameter. Usage should be like this: `/api/v1/source?src=forum=your_parameter,market=your_parameter`", "error")
ctx.JSON(http.StatusNotFound, gin.H{"Error": "Please pass a argument to parameter. Usage should be like this: `/api/v1/source?src=forum=your_parameter,market=your_parameter`"})
ctx.JSON(http.StatusBadRequest, gin.H{"Error": "Please pass a argument to parameter. Usage should be like this: `/api/v1/source?src=forum=your_parameter,market=your_parameter`"})
return
}

Expand All @@ -96,7 +96,7 @@ func GetCTIData(urls string, ctx *gin.Context) {
} else {
logger.Log.Errorln("Please pass a argument to parameter. Usage should be like this: `/api/v1/source?src=ransom=your_parameter,telegram=your_parameter`")
helpers.SendMessageWS("Source", "Please pass a argument to parameter. Usage should be like this: `/api/v1/source?src=ransom=your_parameter,telegram=your_parameter`", "error")
ctx.JSON(http.StatusNotFound, gin.H{"Error": "Please pass a argument to parameter. Usage should be like this: `/api/v1/source?src=ransom=your_parameter,telegram=your_parameter`"})
ctx.JSON(http.StatusBadRequest, gin.H{"Error": "Please pass a argument to parameter. Usage should be like this: `/api/v1/source?src=ransom=your_parameter,telegram=your_parameter`"})
return
}
}
Expand Down Expand Up @@ -312,7 +312,7 @@ func filterSourceOutputs(ctx *gin.Context) {
}
default:
logger.Log.Errorln("Please pass a valid parameter.")
ctx.JSON(http.StatusNotFound, gin.H{"error": "Please pass a valid parameter."})
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "Please pass a valid parameter."})
helpers.SendMessageWS("Source", fmt.Sprintln("Please pass a valid parameter."), "error")
}
}
Expand Down
Loading

0 comments on commit a0784d7

Please sign in to comment.