logixlysia 2.2.3 → 2.3.0
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/.gitguardian.yml +16 -0
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/index.ts +3 -2
- package/src/logger.ts +23 -0
- package/src/types/HttpError.ts +11 -0
package/.gitguardian.yml
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Required, otherwise ggshield considers the file to use the deprecated v1 format
|
|
2
|
+
version: 2
|
|
3
|
+
|
|
4
|
+
# Set to true if the desired exit code for the CLI is always 0, otherwise the
|
|
5
|
+
# exit code will be 1 if incidents are found.
|
|
6
|
+
exit-zero: false
|
|
7
|
+
|
|
8
|
+
verbose: false
|
|
9
|
+
|
|
10
|
+
instance: https://dashboard.gitguardian.com
|
|
11
|
+
|
|
12
|
+
# Maximum commits to scan in a hook.
|
|
13
|
+
max-commits-for-hook: 50
|
|
14
|
+
|
|
15
|
+
# Accept self-signed certificates for the API.
|
|
16
|
+
allow-self-signed: false
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.3.0](https://github.com/PunGrumpy/logixlysia/compare/v2.2.3...v2.3.0) (2024-04-06)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **logger:** handle HTTP errors and log with appropriate status code ([276b3c4](https://github.com/PunGrumpy/logixlysia/commit/276b3c41334bcf1cefd032ae11f71fb8cda2bc9a)), closes [#24](https://github.com/PunGrumpy/logixlysia/issues/24)
|
|
9
|
+
|
|
3
10
|
## [2.2.3](https://github.com/PunGrumpy/logixlysia/compare/v2.2.2...v2.2.3) (2024-04-06)
|
|
4
11
|
|
|
5
12
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Elysia from 'elysia'
|
|
2
|
-
import { createLogger } from './logger'
|
|
2
|
+
import { createLogger, handleHttpError } from './logger'
|
|
3
3
|
import startString from './utils/start'
|
|
4
4
|
import { Server } from 'bun'
|
|
5
5
|
import { Options } from './options'
|
|
@@ -51,7 +51,8 @@ export const logger = (options?: Options): Elysia => {
|
|
|
51
51
|
)
|
|
52
52
|
})
|
|
53
53
|
.onError({ as: 'global' }, ({ request, error, store }) => {
|
|
54
|
-
log.log('ERROR', request, error, store as { beforeTime: bigint })
|
|
54
|
+
// log.log('ERROR', request, error, store as { beforeTime: bigint })
|
|
55
|
+
handleHttpError(request, error, store as { beforeTime: bigint })
|
|
55
56
|
})
|
|
56
57
|
|
|
57
58
|
return elysia
|
package/src/logger.ts
CHANGED
|
@@ -7,6 +7,7 @@ import statusString from './utils/status'
|
|
|
7
7
|
import { RequestInfo } from './types/RequestInfo'
|
|
8
8
|
import { LogData, LogLevel, Logger } from './types/Logger'
|
|
9
9
|
import { StoreData } from './types/StoreData'
|
|
10
|
+
import { HttpError } from './types/HttpError'
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Asynchronously logs a message constructed from various log components.
|
|
@@ -88,3 +89,25 @@ function writeToLogAsync(message: string): Promise<void> {
|
|
|
88
89
|
export const createLogger = (): Logger => ({
|
|
89
90
|
log: (level, request, data, store) => log(level, request, data, store)
|
|
90
91
|
})
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Handle HTTP errors and log them with the appropriate status code.
|
|
95
|
+
*
|
|
96
|
+
* @param {RequestInfo} request - The request information.
|
|
97
|
+
* @param {Error} error - The error object.
|
|
98
|
+
* @param {StoreData} store - The store data.
|
|
99
|
+
*/
|
|
100
|
+
export const handleHttpError = (
|
|
101
|
+
request: RequestInfo,
|
|
102
|
+
error: Error,
|
|
103
|
+
store: StoreData
|
|
104
|
+
): void => {
|
|
105
|
+
const statusCode = error instanceof HttpError ? error.status : 500
|
|
106
|
+
const logMessage = buildLogMessage(
|
|
107
|
+
'ERROR',
|
|
108
|
+
request,
|
|
109
|
+
{ status: statusCode },
|
|
110
|
+
store
|
|
111
|
+
)
|
|
112
|
+
console.error(logMessage)
|
|
113
|
+
}
|