@stacksjs/error-handling 0.59.8 → 0.59.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -386,8 +386,10 @@ class ErrorHandler {
386
386
  }
387
387
  static async writeErrorToFile(err) {
388
388
  const formattedError = `[${new Date().toISOString()}] ${err.name}: ${err.message}\n`;
389
+ const errorsLogFilePath = logsPath("errors.log");
389
390
  try {
390
- await fs.appendFile(logFilePath, formattedError);
391
+ await fs.mkdir(dirname(errorsLogFilePath), { recursive: true });
392
+ await fs.appendFile(errorsLogFilePath, formattedError);
391
393
  } catch (error) {
392
394
  console.error("Failed to write to error file:", error);
393
395
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/error-handling",
3
3
  "type": "module",
4
- "version": "0.59.8",
4
+ "version": "0.59.9",
5
5
  "description": "Type safe error handling.",
6
6
  "author": "Chris Breuer",
7
7
  "license": "MIT",
package/src/handler.ts CHANGED
@@ -30,8 +30,13 @@ export class ErrorHandler {
30
30
 
31
31
  static async writeErrorToFile(err: Error) {
32
32
  const formattedError = `[${new Date().toISOString()}] ${err.name}: ${err.message}\n`
33
+ const errorsLogFilePath = logsPath('errors.log')
34
+
33
35
  try {
34
- await fs.appendFile(logFilePath, formattedError)
36
+ // Ensure the directory exists
37
+ await fs.mkdir(dirname(errorsLogFilePath), { recursive: true })
38
+ // Append the message to the log file
39
+ await fs.appendFile(errorsLogFilePath, formattedError)
35
40
  }
36
41
  catch (error) {
37
42
  console.error('Failed to write to error file:', error)