Skip to content

Commit

Permalink
Do not log invalid body exceptions in Http4s. (#532)
Browse files Browse the repository at this point in the history
* Do not log invelid body exceptions in Http4s.

* Fix pure TS build.

* Update @types/websocket.
  • Loading branch information
Caparow committed Aug 1, 2024
1 parent 340bf99 commit 05d3329
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object YarnOptions {
ManifestDependency("moment", "^2.29.1"),
ManifestDependency("websocket", "^1.0.32"),
ManifestDependency("@types/node", "^14.14.6"),
ManifestDependency("@types/websocket", "^1.0.1"),
ManifestDependency("@types/websocket", "^1.0.10"),
),
devDependencies = List(
ManifestDependency("typescript", "^4.5.5")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class HttpServer[F[+_, +_]: IO2: Temporal2: Primitives2: UnsafeRun2, AuthCtx](
) {
import dsl.*
// WS Response attribute key, to differ from usual HTTP responses
private val wsAttributeKey = UnsafeRun2[F].unsafeRun(Key.newKey[F[Throwable, _], WsResponseMarker.type])
protected final val wsAttributeKey = UnsafeRun2[F].unsafeRun(Key.newKey[F[Throwable, _], WsResponseMarker.type])

protected val serverMuxer: IRTServerMultiplexor[F, AuthCtx] = IRTServerMultiplexor.combine(contextServices.map(_.authorizedMuxer))
protected val wsContextsSessions: Set[WsContextSessions.AnyContext[F, AuthCtx]] = contextServices.map(_.authorizedWsSessions)
Expand Down Expand Up @@ -233,8 +233,8 @@ class HttpServer[F[+_, +_]: IO2: Temporal2: Primitives2: UnsafeRun2, AuthCtx](
logger.info(s"${req.method.name -> "method"} ${req.pathInfo -> "uri"}: rejection, ${resp.status.code -> "code"} ${resp.status.reason -> "reason"}")
}
} yield resp).tapError {
cause =>
logger.error(s"${req.method.name -> "method"} ${req.pathInfo -> "path"}: failure, $cause")
case cause: InvalidBodyException => logger.debug(s"${req.method.name -> "method"} ${req.pathInfo -> "path"}: invalid body, $cause")
case cause => logger.error(s"${req.method.name -> "method"} ${req.pathInfo -> "path"}: failure, $cause")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export class JSONMarshallerImpl implements JSONMarshaller {
return toRaw ? {} : '{}';
}

const serialized = typeof data['serialize'] === 'function' ? data['serialize']() : data;
const dataAny = data as any;
const serialized = typeof dataAny['serialize'] === 'function' ? dataAny['serialize']() : data;
if (toRaw) {
return serialized;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class HttpServerGeneric<C> {
protected requestHandler(request: http.IncomingMessage, response: http.ServerResponse) {
const { method, url, headers } = request;

let respHeaders = {};
let respHeaders: any = {};
// IE8 does not allow domains to be specified, just the *
// headers["Access-Control-Allow-Origin"] = req.headers.origin;
respHeaders['Access-Control-Allow-Origin'] = '*';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class TypeScriptTranslator(ts: Typespace, options: TypescriptTranslatorOptions)
|
| public static deserialize(data: ${name}Serialized): $name {
| const id = Object.keys(data)[0];
| const content = data[id];
| const content = (data as any)[id];
| switch (id) {
| case 'Success': return new EitherRight<$leftTypeName, $rightTypeName>($rightTypeDeserialize);
| case 'Failure': return new EitherLeft<$leftTypeName, $rightTypeName>($leftTypeDeserialize);
Expand Down Expand Up @@ -425,7 +425,7 @@ class TypeScriptTranslator(ts: Typespace, options: TypescriptTranslatorOptions)
}
).mkString(" | ")}}): $name {
| const id = Object.keys(data)[0];
| const content = data[id];
| const content = (data as any)[id];
| switch (id) {
|${alternatives.map(a => "case '" + a.wireId + "': return " + conv.deserializeType("content", a.typeId, typespace, asAny = true) + ";").mkString("\n").shift(12)}
| default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class TypescriptLayouter(options: TypescriptTranslatorOptions) extends Translati
"ignoreDeprecations": "5.0",
"experimentalDecorators": true,
"removeComments": true,
"preserveConstEnums": true
"preserveConstEnums": true,
"skipLibCheck": true
},
"compileOnSave": false
}
Expand Down Expand Up @@ -123,7 +124,8 @@ class TypescriptLayouter(options: TypescriptTranslatorOptions) extends Translati
"ignoreDeprecations": "5.0",
"experimentalDecorators": true,
"removeComments": true,
"preserveConstEnums": true
"preserveConstEnums": true,
"skipLibCheck": true
},
"compileOnSave": false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TypeScriptTypeConverter() {
case Primitive.TTsTz => "Date.parse(" + value + ")"
case Primitive.TTsU => "Date.parse(" + value + ")"
case id: IdentifierId => s"new ${id.name}($value)"
case en: EnumId => s"${en.name}[$value]"
case en: EnumId => s"${en.name}[$value as keyof typeof ${en.name}]"
// TODO We do nothing for other types, should probably figure something out ...
case _ => throw new Exception("Unsupported area in parseTypeFromString")
}
Expand Down Expand Up @@ -103,7 +103,7 @@ class TypeScriptTypeConverter() {

def deserializeGenericType(variable: String, target: Generic, ts: Typespace, asAny: Boolean = false): String = target match {
case gm: Generic.TMap =>
s"Object.keys($variable).reduce((previous, current) => {previous[current] = ${deserializeType(s"$variable[current]", gm.valueType, ts, asAny)}; return previous; }, {})"
s"Object.keys($variable).reduce<any>((previous, current) => {previous[current] = ${deserializeType(s"$variable[current]", gm.valueType, ts, asAny)}; return previous; }, {})"
case gl: Generic.TList =>
gl.valueType match {
case _: Primitive => s"$variable.slice()"
Expand All @@ -123,7 +123,7 @@ class TypeScriptTypeConverter() {
case d: DTOId => s"new ${d.name}(${variable + (if (asAny) " as any" else "")})"
case al: AliasId => deserializeType(variable, ts.dealias(al), ts, asAny)
case id: IdentifierId => s"new ${id.name}(${variable + (if (asAny) " as any" else "")})"
case en: EnumId => s"${en.name}[$variable]"
case en: EnumId => s"${en.name}[$variable as keyof typeof ${en.name}]"

case _ => s"'$variable: Error here! Not Implemented! ${target.name}'"
}
Expand Down Expand Up @@ -239,7 +239,7 @@ class TypeScriptTypeConverter() {

def serializeGeneric(name: String, id: TypeId, ts: Typespace, asAny: Boolean = false): String = id match {
case m: Generic.TMap =>
s"Object.keys($name).reduce((previous, current) => {previous[current] = ${serializeValue(s"$name[current]", m.valueType, ts, nonMember = true)}; return previous; }, {})"
s"Object.keys($name).reduce<any>((previous, current) => {previous[current] = ${serializeValue(s"$name[current]", m.valueType, ts, nonMember = true)}; return previous; }, {})"
case s: Generic.TSet =>
s.valueType match {
case _: Primitive => s"$name.slice()"
Expand Down

0 comments on commit 05d3329

Please sign in to comment.