Skip to content

Commit f9a7a78

Browse files
authored
refactor: reuse standard response methods for kicks (#1701)
Reuse `SlackResponse.Warn` and `SlackResponse.Err` from the kick response through a value conversion, removing 17 lines of duplicated logic. Both structs have the same fields; their differing JSON tags do not affect the conversion. Preserve the custom kick-response decoder, warning and error details, and the public API. Validation: affected kick, response, warning, and scope-diagnostic tests pass, along with formatting, lint, module, and whitespace checks.
1 parent c08d142 commit f9a7a78

1 file changed

Lines changed: 2 additions & 19 deletions

File tree

‎misc.go‎

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -215,29 +215,12 @@ func (s *KickUserFromConversationSlackResponse) UnmarshalJSON(data []byte) error
215215
// Warn returns warning information from the API response, or nil if there
216216
// are no warnings.
217217
func (s KickUserFromConversationSlackResponse) Warn() *Warning {
218-
if s.Warning == "" && len(s.ResponseMetadata.Warnings) == 0 {
219-
return nil
220-
}
221-
return &Warning{
222-
Codes: strings.Split(s.Warning, ","),
223-
Warnings: s.ResponseMetadata.Warnings,
224-
}
218+
return SlackResponse(s).Warn()
225219
}
226220

227221
// Err returns any API error present in the response.
228222
func (s KickUserFromConversationSlackResponse) Err() error {
229-
if s.Ok {
230-
return nil
231-
}
232-
233-
// handle pure text based responses like chat.post
234-
// which while they have a slack response in their data structure
235-
// it doesn't actually get set during parsing.
236-
if strings.TrimSpace(s.Error) == "" {
237-
return nil
238-
}
239-
240-
return SlackErrorResponse{Err: s.Error, Errors: s.Errors, ResponseMetadata: s.ResponseMetadata, Needed: s.Needed, Provided: s.Provided}
223+
return SlackResponse(s).Err()
241224
}
242225

243226
func (t SlackResponse) Err() error {

0 commit comments

Comments
 (0)