fix: Throw error before getting slack messages for find messages action
This commit is contained in:
@@ -7,12 +7,7 @@ export default class FindMessages {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
async run(
|
||||
query: string,
|
||||
sortBy: string,
|
||||
sortDirection: string,
|
||||
count = 1,
|
||||
) {
|
||||
async run(query: string, sortBy: string, sortDirection: string, count = 1) {
|
||||
const headers = {
|
||||
Authorization: `Bearer ${this.client.connection.formattedData.accessToken}`,
|
||||
};
|
||||
@@ -24,27 +19,26 @@ export default class FindMessages {
|
||||
count,
|
||||
};
|
||||
|
||||
const response = await this.client.httpClient.get(
|
||||
'/search.messages',
|
||||
{ headers, params }
|
||||
);
|
||||
const response = await this.client.httpClient.get('/search.messages', {
|
||||
headers,
|
||||
params,
|
||||
});
|
||||
|
||||
const data = response.data;
|
||||
const messages = data.messages.matches;
|
||||
const message = messages?.[0];
|
||||
|
||||
if (!data.ok) {
|
||||
if (data.error === 'missing_scope') {
|
||||
throw new Error(
|
||||
`Error occured while finding messages; ${data.error}: ${data.needed}`
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Error occured while finding messages; ${data.error}`
|
||||
);
|
||||
throw new Error(`Error occured while finding messages; ${data.error}`);
|
||||
}
|
||||
|
||||
const messages = data.messages.matches;
|
||||
const message = messages?.[0];
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user