Use constant instead of magic number

This commit is contained in:
Lars Strojny 2022-11-24 20:18:48 +01:00
parent e5b3a90fae
commit f30dfe0cee
No known key found for this signature in database
GPG key ID: 887416A2AD3B0CA9

View file

@ -1,5 +1,6 @@
import Fastify, { type FastifyReply, type FastifyRequest, type HookHandlerDoneFunction } from 'fastify' import Fastify, { type FastifyReply, type FastifyRequest, type HookHandlerDoneFunction } from 'fastify'
import { readFileSync } from 'fs' import { readFileSync } from 'fs'
import { constants as HttpConstants } from 'http2'
import { isAuthenticated } from '../../security' import { isAuthenticated } from '../../security'
import type { HttpAdapter, HttpResponse, HttpServer } from './api' import type { HttpAdapter, HttpResponse, HttpServer } from './api'
import fastifyAuth from '@fastify/auth' import fastifyAuth from '@fastify/auth'
@ -68,8 +69,8 @@ export const fastifyServe: HttpAdapter = async (server: HttpServer) => {
} }
fastify.addHook('onResponse', (request: FastifyRequest, reply: FastifyReply) => { fastify.addHook('onResponse', (request: FastifyRequest, reply: FastifyReply) => {
if (reply.statusCode >= 400) { if (reply.statusCode >= HttpConstants.HTTP_STATUS_BAD_REQUEST) {
server.log?.warn(formatCombinedLog(request, reply)) server.log?.error(formatCombinedLog(request, reply))
} else if (server.config.debug) { } else if (server.config.debug) {
server.log?.debug(formatCombinedLog(request, reply)) server.log?.debug(formatCombinedLog(request, reply))
} }