Merge pull request #12957 from medusajs/only-log-server-errors
fix: only log server errors
This commit is contained in:
@@ -9,14 +9,14 @@ import express from "express"
|
||||
import querystring from "querystring"
|
||||
import supertest from "supertest"
|
||||
|
||||
import { config } from "../mocks"
|
||||
import { MedusaContainer } from "@medusajs/types"
|
||||
import { configManager } from "../../../config"
|
||||
import { container } from "../../../container"
|
||||
import { featureFlagsLoader } from "../../../feature-flags"
|
||||
import { logger } from "../../../logger"
|
||||
import { MedusaRequest } from "../../types"
|
||||
import { ApiLoader } from "../../router"
|
||||
import { MedusaRequest } from "../../types"
|
||||
import { config } from "../mocks"
|
||||
|
||||
function asArray(resolvers) {
|
||||
return {
|
||||
@@ -69,6 +69,7 @@ export const createServer = async (rootDir) => {
|
||||
container.register({
|
||||
logger: asValue({
|
||||
error: () => {},
|
||||
info: () => {},
|
||||
}),
|
||||
manager: asValue({}),
|
||||
})
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { ErrorRequestHandler, NextFunction, Response } from "express"
|
||||
import { fromZodIssue } from "zod-validation-error"
|
||||
import { NextFunction, ErrorRequestHandler, Response } from "express"
|
||||
|
||||
import { ContainerRegistrationKeys, MedusaError } from "@medusajs/utils"
|
||||
import { formatException } from "./exception-formatter"
|
||||
import { MedusaRequest } from "../types"
|
||||
import { formatException } from "./exception-formatter"
|
||||
|
||||
const QUERY_RUNNER_RELEASED = "QueryRunnerAlreadyReleasedError"
|
||||
const TRANSACTION_STARTED = "TransactionAlreadyStartedError"
|
||||
@@ -31,7 +31,6 @@ export function errorHandler() {
|
||||
}
|
||||
|
||||
err = formatException(err)
|
||||
logger.error(err)
|
||||
|
||||
const errorType = err.type || err.name
|
||||
const errObj = {
|
||||
@@ -82,6 +81,12 @@ export function errorHandler() {
|
||||
break
|
||||
}
|
||||
|
||||
if (statusCode >= 500) {
|
||||
logger.error(err)
|
||||
} else {
|
||||
logger.info(err.message)
|
||||
}
|
||||
|
||||
if ("issues" in err && Array.isArray(err.issues)) {
|
||||
const messages = err.issues.map((issue) => fromZodIssue(issue).toString())
|
||||
res.status(statusCode).json({
|
||||
|
||||
Reference in New Issue
Block a user