Skip to content

Commit

Permalink
fix: update error handling based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Mar 15, 2024
1 parent 333d629 commit ea46572
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions api/adapter/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func insert(c *fiber.Ctx) error {

err := computeAdapterHash(payload, true)
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString("failed to compute adapter hash: " + err.Error())
return c.Status(fiber.StatusInternalServerError).SendString(err.Error())
}

row, err := utils.QueryRow[AdapterIdModel](c, InsertAdapter, map[string]any{
Expand Down Expand Up @@ -106,7 +106,7 @@ func hash(c *fiber.Ctx) error {

err = computeAdapterHash(&payload, verify)
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString("failed to compute adapter hash: " + err.Error())
return c.Status(fiber.StatusInternalServerError).SendString(err.Error())
}
return c.JSON(payload)
}
Expand Down Expand Up @@ -153,13 +153,14 @@ func computeAdapterHash(data *AdapterInsertModel, verify bool) error {

out, err := json.Marshal(input)
if err != nil {
return err
return fmt.Errorf("failed to compute adapter hash: %s", err.Error())
}

hash := crypto.Keccak256Hash([]byte(out))
hashString := fmt.Sprintf("0x%x", hash)
if verify && data.AdapterHash != hashString {
return fmt.Errorf("hashes do not match!\nexpected %s, received %s", hashString, data.AdapterHash)
hashComputeErr := fmt.Errorf("hashes do not match!\nexpected %s, received %s", hashString, data.AdapterHash)
return fmt.Errorf("failed to compute adapter hash: %s", hashComputeErr.Error())
}

data.AdapterHash = hashString
Expand Down
9 changes: 5 additions & 4 deletions api/aggregator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func insert(c *fiber.Ctx) error {
}
err = computeAggregatorHash(&hashComputeParam, true)
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString("failed to compute aggregator hash: " + err.Error())
return c.Status(fiber.StatusInternalServerError).SendString(err.Error())
}

insertParam := _AggregatorInsertModel{
Expand Down Expand Up @@ -208,7 +208,7 @@ func hash(c *fiber.Ctx) error {

err = computeAggregatorHash(&hashComputeParam, verify)
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString("failed to compute aggregator hash: " + err.Error())
return c.Status(fiber.StatusInternalServerError).SendString(err.Error())
}

return c.JSON(hashComputeParam)
Expand Down Expand Up @@ -314,13 +314,14 @@ func computeAggregatorHash(data *AggregatorHashComputeInputModel, verify bool) e
processData := input.AggregatorHashComputeProcessModel
out, err := json.Marshal(processData)
if err != nil {
return err
return fmt.Errorf("failed to compute adapter hash: %s", err.Error())
}

hash := crypto.Keccak256Hash([]byte(out))
hashString := fmt.Sprintf("0x%x", hash)
if verify && data.AggregatorHash != hashString {
return fmt.Errorf("hashes do not match!\nexpected %s, received %s", hashString, data.AdapterHash)
hashComputeErr := fmt.Errorf("hashes do not match!\nexpected %s, received %s", hashString, data.AggregatorHash)
return fmt.Errorf("failed to compute adapter hash: %s", hashComputeErr.Error())
}

data.AggregatorHash = hashString
Expand Down

0 comments on commit ea46572

Please sign in to comment.