Skip to content

Commit

Permalink
fix(DiscordRESTError): handle null reponses properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah committed Jun 12, 2024
1 parent 13e8c8b commit c634ab1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/rest/DiscordRESTError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class DiscordRESTError extends Error {
/**
* @param req A client request
* @param res An incoming message from the server
* @param response Any {@link Server}s response class
* @param response A response's body
* @param stack The error stack
*/
constructor(req: Request, res: Response, response: any, stack: string) {
Expand All @@ -30,9 +30,9 @@ export class DiscordRESTError extends Error {
this.response = response;
this.code = res.status;

let message = response.message || 'Unknown error';
if (response.errors) message += '\n ' + this.flattenErrors(response.errors).join('\n ');
else {
let message = response?.message || 'Unknown error';
if (response?.errors) message += '\n ' + this.flattenErrors(response.errors).join('\n ');
else if (response) {
const errors = this.flattenErrors(response);
if (errors.length > 0) message += '\n ' + errors.join('\n ');
}
Expand Down

0 comments on commit c634ab1

Please sign in to comment.