| 131 | } |
| 132 | |
| 133 | func ResetStatusCode(newApiErr *types.NewAPIError, statusCodeMappingStr string) { |
| 134 | if newApiErr == nil { |
| 135 | return |
| 136 | } |
| 137 | if statusCodeMappingStr == "" || statusCodeMappingStr == "{}" { |
| 138 | return |
| 139 | } |
| 140 | statusCodeMapping := make(map[string]any) |
| 141 | err := common.Unmarshal([]byte(statusCodeMappingStr), &statusCodeMapping) |
| 142 | if err != nil { |
| 143 | return |
| 144 | } |
| 145 | if newApiErr.StatusCode == http.StatusOK { |
| 146 | return |
| 147 | } |
| 148 | codeStr := strconv.Itoa(newApiErr.StatusCode) |
| 149 | if value, ok := statusCodeMapping[codeStr]; ok { |
| 150 | intCode, ok := parseStatusCodeMappingValue(value) |
| 151 | if !ok { |
| 152 | return |
| 153 | } |
| 154 | newApiErr.StatusCode = intCode |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | func parseStatusCodeMappingValue(value any) (int, bool) { |
| 159 | switch v := value.(type) { |