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 [ ])
Requirements (place an x in each of the [ ])
Bug Report
Filling out the following details about bugs will help us solve your issue sooner.
Packages:
Select all that apply:
Reproducible in:
package version: 4.12.0
node version: 10.15.3
OS version(s): Arch Linux 5.0.7
Steps to reproduce:
- Call
users.lookupByEmail for a team where the email is not registered.
const result = await client.users.lookupByEmail({ email: 'foo@bar.com' })
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.
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
xin one of the[ ])Requirements (place an
xin each of the[ ])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/webhooksReproducible in:
package version: 4.12.0
node version: 10.15.3
OS version(s): Arch Linux 5.0.7
Steps to reproduce:
users.lookupByEmailfor a team where the email is not registered.Expected result:
Since the interface
WepAPICallResulthas the following shape, in particular theerrorandokproperties:I expect that the call to
lookupByEmailshould resolve to an object similar to:I.e., the
errorproperty indicates that there was an error executing the particular lookup.Actual result:
The call rejected to an Error object containing:
Discussion:
I believe the simplest solution would be to simply not include
errorin the interfaceWebAPICallResult. 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
Errorand 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.errororresponse.okproperty in our application code and act accordingly. But that would obviously be a breaking change.