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:
		| @@ -9,17 +9,17 @@ | ||||
|   "author": "Lossless GmbH", | ||||
|   "license": "MIT", | ||||
|   "scripts": { | ||||
|     "test": "(tstest test/)", | ||||
|     "test": "(tstest test/ --verbose)", | ||||
|     "build": "(tsbuild --web --allowimplicitany)", | ||||
|     "format": "(gitzone format)", | ||||
|     "buildDocs": "tsdoc" | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|     "@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/tapbundle": "^6.0.3", | ||||
|     "@types/node": "^24.7.2" | ||||
|     "@types/node": "^22.0.0" | ||||
|   }, | ||||
|   "dependencies": { | ||||
|     "@push.rocks/smartfile": "^11.2.7", | ||||
|   | ||||
							
								
								
									
										1586
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1586
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -66,4 +66,4 @@ tap.test('should retrieve a mail using a retrieval url', async () => { | ||||
|   } | ||||
| }); | ||||
|  | ||||
| tap.start(); | ||||
| export default tap.start(); | ||||
|   | ||||
| @@ -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