fix: correct Mailgun API URL and enhance error handling in MailgunAccount class
- Fixed the incorrect API URL in MailgunAccount class. - Improved error handling for email sending failures by providing detailed error messages based on response content. - Updated test file to export the tap.start() function for better module integration.
This commit is contained in:
@@ -18,7 +18,7 @@ export class MailgunAccount {
|
||||
this.apiBaseUrl =
|
||||
this.options.region === 'eu'
|
||||
? 'https://api.eu.mailgun.net/v3'
|
||||
: 'https://api..mailgun.net/v3';
|
||||
: 'https://api.mailgun.net/v3';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,8 +127,24 @@ export class MailgunAccount {
|
||||
);
|
||||
return await response.json();
|
||||
} else {
|
||||
console.log(await response.json());
|
||||
throw new Error('could not send email');
|
||||
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
||||
try {
|
||||
// Get response body as text first
|
||||
const errorText = await response.text();
|
||||
console.log(errorText);
|
||||
|
||||
// Try to parse as JSON
|
||||
try {
|
||||
const errorBody = JSON.parse(errorText);
|
||||
errorMessage = errorBody.message || JSON.stringify(errorBody);
|
||||
} catch {
|
||||
// Not JSON, use plain text
|
||||
errorMessage = errorText || errorMessage;
|
||||
}
|
||||
} catch {
|
||||
// Couldn't read body at all
|
||||
}
|
||||
throw new Error(`could not send email: ${errorMessage}`);
|
||||
}
|
||||
} else {
|
||||
console.log(
|
||||
|
||||
Reference in New Issue
Block a user