Skip to content

WebAPICallResult and the error handling is not intuitive #775

Open
@lenkan

Description

@lenkan

Description

This is not really a bug, but rather a feature of the API that caught me off guard. I think there is room for improvement for how errors are propagated back to the user from the WebClient. See "Steps to reproduce" for an explanation of what surprised me.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Packages:

Select all that apply:

  • @slack/web-api
  • @slack/events-api
  • @slack/interactive-messages
  • @slack/rtm-api
  • @slack/webhooks
  • I don't know

Reproducible in:

package version: 4.12.0

node version: 10.15.3

OS version(s): Arch Linux 5.0.7

Steps to reproduce:

  1. Call users.lookupByEmail for a team where the email is not registered.
const result = await client.users.lookupByEmail({ email: '[email protected]' })

Expected result:

Since the interface WepAPICallResult has the following shape, in particular the error and ok properties:

export interface WebAPICallResult {
  ok: boolean;
  error?: string;
  response_metadata?: {
    warnings?: string[];
    next_cursor?: string;
    scopes?: string[];
    acceptedScopes?: string[];
    retryAfter?: number;
  };
  [key: string]: unknown;
}

I expect that the call to lookupByEmail should resolve to an object similar to:

{
   error: 'users_not_found',
   ok: false,
   response_metadata: [...]
}

I.e., the error property indicates that there was an error executing the particular lookup.

Actual result:

The call rejected to an Error object containing:

{ 
  message: 'An API error occurred: users_not_found',
  code: 'slackclient_platform_error',
  data: { 
     ok: false,
     error: 'users_not_found',
  } 
}

Discussion:

I believe the simplest solution would be to simply not include error in the interface WebAPICallResult. This would change the public interface as it is communicated, but not how it actually works (?).

As far as I can see from the source, the returned value never specifies a value for this property. When the client receives a non-OK HTTP response, it simply wraps this into an Error and throw instead. Please correct me if I am mistaking.

With that being said, I do not really see the value of rejecting the API-call unless there actually is an unexpected Error, such as a network error or a bug. That way, we can simply check the response.error or response.ok property in our application code and act accordingly. But that would obviously be a breaking change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:typescriptissues that specifically impact using the package from typescript projectsauto-triage-skipdiscussionM-T: An issue where more input is needed to reach a decisionpkg:web-apiapplies to `@slack/web-api`semver:major

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions