-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathexample.ts
More file actions
27 lines (21 loc) · 665 Bytes
/
example.ts
File metadata and controls
27 lines (21 loc) · 665 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { consola } from 'consola'
const statusMap = {
'200': 'OK',
'404': 'Not Found',
'500': 'Internal Server Error',
'403': 'Forbidden',
'400': 'Bad Request',
}
const errorCodes = ['404', '500', '403', '400', '400', '404']
export const add = (a: number, b: number): number => a + b
export const log = async <T extends string>(input: T): Promise<void> => {
const status = input.match(/\d{3}/)?.[0] || '200'
let message: string
if (statusMap[status])
message = statusMap[status]
else
message = 'Unknown Status Code'
consola[errorCodes.includes(status) ? 'error' : 'info'](
`Status Code: ${status} - Message: ${message}`,
)
}