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:
2025-10-17 08:48:22 +00:00
parent 2c88f50625
commit d0686ecfe8
4 changed files with 812 additions and 804 deletions

View File

@@ -9,17 +9,17 @@
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/ --verbose)",
"build": "(tsbuild --web --allowimplicitany)", "build": "(tsbuild --web --allowimplicitany)",
"format": "(gitzone format)", "format": "(gitzone format)",
"buildDocs": "tsdoc" "buildDocs": "tsdoc"
}, },
"devDependencies": { "devDependencies": {
"@git.zone/tsbuild": "^2.1.65", "@git.zone/tsbuild": "^2.1.65",
"@git.zone/tstest": "^2.5.0", "@git.zone/tstest": "^2.6.1",
"@push.rocks/qenv": "^6.1.3", "@push.rocks/qenv": "^6.1.3",
"@push.rocks/tapbundle": "^6.0.3", "@push.rocks/tapbundle": "^6.0.3",
"@types/node": "^24.7.2" "@types/node": "^22.0.0"
}, },
"dependencies": { "dependencies": {
"@push.rocks/smartfile": "^11.2.7", "@push.rocks/smartfile": "^11.2.7",

1586
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -66,4 +66,4 @@ tap.test('should retrieve a mail using a retrieval url', async () => {
} }
}); });
tap.start(); export default tap.start();

View File

@@ -18,7 +18,7 @@ export class MailgunAccount {
this.apiBaseUrl = this.apiBaseUrl =
this.options.region === 'eu' this.options.region === 'eu'
? 'https://api.eu.mailgun.net/v3' ? '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(); return await response.json();
} else { } else {
console.log(await response.json()); let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
throw new Error('could not send email'); 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 { } else {
console.log( console.log(