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