-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'CNS-cosmos-47.10' of github.com:lavanet/lava into CNS-c…
…osmos-47.10
- Loading branch information
Showing
8 changed files
with
95 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package common | ||
|
||
import "github.com/gofiber/fiber/v2" | ||
|
||
// ####### | ||
// JsonRPC | ||
// ####### | ||
|
||
type JsonRPCError struct { | ||
Code int `json:"code"` | ||
Message string `json:"message"` | ||
} | ||
|
||
type JsonRPCErrorMessage struct { | ||
JsonRPC string `json:"jsonrpc"` | ||
Id int `json:"id"` | ||
Error JsonRPCError `json:"error"` | ||
} | ||
|
||
var JsonRpcMethodNotFoundError = JsonRPCErrorMessage{ | ||
JsonRPC: "2.0", | ||
Id: 1, | ||
Error: JsonRPCError{ | ||
Code: -32601, | ||
Message: "Method not found", | ||
}, | ||
} | ||
|
||
// ####### | ||
// Rest | ||
// ####### | ||
|
||
type RestError struct { | ||
Code int `json:"code"` | ||
Message string `json:"message"` | ||
Details []interface{} `json:"details"` | ||
} | ||
|
||
var RestMethodNotFoundError = RestError{ | ||
Code: 12, | ||
Message: "Not Implemented", | ||
Details: []interface{}{}, | ||
} | ||
|
||
// ####### | ||
// Rest - Aptos | ||
// ####### | ||
|
||
type RestAptosError struct { | ||
Message string `json:"message"` | ||
ErrorCode string `json:"error_code"` | ||
VmErrorCode interface{} `json:"vm_error_code"` | ||
} | ||
|
||
var RestAptosMethodNotFoundError = RestAptosError{ | ||
Message: "not found", | ||
ErrorCode: "web_framework_error", | ||
VmErrorCode: nil, | ||
} | ||
|
||
func CreateRestMethodNotFoundError(fiberCtx *fiber.Ctx, chainId string) error { | ||
switch chainId { | ||
case "APT1": | ||
// Aptos node returns a different error body than the rest of the chains | ||
// This solution is temporary until we change the spec to state how the error looks like | ||
return fiberCtx.Status(fiber.StatusNotImplemented).JSON(RestAptosMethodNotFoundError) | ||
default: | ||
return fiberCtx.Status(fiber.StatusNotImplemented).JSON(RestMethodNotFoundError) | ||
} | ||
} |