import { StatusCodes } from 'http-status-codes'
import { AbstractUIServer } from './AbstractUIServer.js'
-import { UIServerUtils } from './UIServerUtils.js'
+import { isProtocolAndVersionSupported } from './UIServerUtils.js'
import { BaseError } from '../../exception/index.js'
import {
ApplicationProtocolVersion,
'WWW-Authenticate': 'Basic realm=users'
})
.end(`${StatusCodes.UNAUTHORIZED} Unauthorized`)
- .destroy()
+ res.destroy()
req.destroy()
}
})
this.responseHandlers.set(uuid, res)
try {
const fullProtocol = `${protocol}${version}`
- if (!UIServerUtils.isProtocolAndVersionSupported(fullProtocol)) {
+ if (!isProtocolAndVersionSupported(fullProtocol)) {
throw new BaseError(`Unsupported UI protocol version: '${fullProtocol}'`)
}
this.registerProtocolVersionUIService(version)
bodyBuffer.push(chunk)
})
.on('end', () => {
- const body = JSON.parse(Buffer.concat(bodyBuffer).toString()) as RequestPayload
+ let requestPayload: RequestPayload | undefined
+ try {
+ requestPayload = JSON.parse(Buffer.concat(bodyBuffer).toString()) as RequestPayload
+ } catch (error) {
+ this.sendResponse(
+ this.buildProtocolResponse(uuid, {
+ status: ResponseStatus.FAILURE,
+ errorMessage: (error as Error).message,
+ errorStack: (error as Error).stack
+ })
+ )
+ return
+ }
this.uiServices
.get(version)
- ?.requestHandler(this.buildProtocolRequest(uuid, procedureName, body))
+ ?.requestHandler(this.buildProtocolRequest(uuid, procedureName, requestPayload))
.then((protocolResponse?: ProtocolResponse) => {
if (protocolResponse != null) {
this.sendResponse(protocolResponse)