From 5c21f22a731090b50d03ffee1c5018cae9ef91fd Mon Sep 17 00:00:00 2001 From: kukugi Date: Thu, 13 Aug 2020 14:40:34 +0900 Subject: [PATCH] Make Http status mapping registrable --- types/rest/http_status_table.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/types/rest/http_status_table.go b/types/rest/http_status_table.go index 701c8fef0f..fafa053bba 100644 --- a/types/rest/http_status_table.go +++ b/types/rest/http_status_table.go @@ -1,6 +1,6 @@ package rest -//TODO : Intergrate http status mapping for every REST API +//TODO : Integrate http status mapping for every REST API import ( "net/http" @@ -14,11 +14,16 @@ type HTTPStatusMappingTable map[string]map[uint32]int var ( table = HTTPStatusMappingTable{ errors.RootCodespace: { - 9: http.StatusNotFound, + errors.ErrUnknownAddress.ABCICode(): http.StatusNotFound, }, } ) +func RegisterHTTPStatusMapping(rawErr error, httpStatus int) { + err := parsingError(rawErr) + table[err.Codespace()][err.ABCICode()] = httpStatus +} + func parsingError(rawErr error) *errors.Error { if rawErr == nil { return nil