Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85658225a3 | ||
|
|
fc8bfb6691 |
@@ -89,7 +89,12 @@ async function postMetrics(metrics: Edge5ModbusV3Metric[]): Promise<void> {
|
|||||||
throw new Error(text || `${response.status} ${response.statusText}`)
|
throw new Error(text || `${response.status} ${response.statusText}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
void postDemoCloudIngest(metric); // для демо-системы
|
const demoResponse = await postDemoCloudIngest(metric); // для демо-системы
|
||||||
|
|
||||||
|
if (!demoResponse.ok) {
|
||||||
|
const text = await demoResponse.text()
|
||||||
|
throw new Error(text || `${demoResponse.status} ${demoResponse.statusText}`)
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : String(error)
|
const message = error instanceof Error ? error.message : String(error)
|
||||||
|
|||||||
@@ -1,9 +1,42 @@
|
|||||||
import { resolveHandler } from './registry.js'
|
import { resolveHandler } from './registry.js'
|
||||||
|
|
||||||
|
type ErrorWithCause = Error & {
|
||||||
|
cause?: unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
type NodeError = Error & {
|
||||||
|
code?: string
|
||||||
|
address?: string
|
||||||
|
port?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
function getErrorCause(error: Error): NodeError | null {
|
||||||
|
const cause = (error as ErrorWithCause).cause
|
||||||
|
return cause instanceof Error ? (cause as NodeError) : null
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatHandlerError(error: unknown): object {
|
||||||
|
if (!(error instanceof Error)) {
|
||||||
|
return { message: String(error) }
|
||||||
|
}
|
||||||
|
|
||||||
|
const cause = getErrorCause(error)
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: error.message,
|
||||||
|
cause: cause?.message,
|
||||||
|
code: cause?.code,
|
||||||
|
address: cause?.address,
|
||||||
|
port: cause?.port,
|
||||||
|
stack: error.stack,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function routeMessage(
|
export async function routeMessage(
|
||||||
topic: string,
|
topic: string,
|
||||||
payload: Buffer,
|
payload: Buffer,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
try {
|
||||||
const handler = resolveHandler(topic)
|
const handler = resolveHandler(topic)
|
||||||
|
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
@@ -11,9 +44,8 @@ export async function routeMessage(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
await handler(topic, payload)
|
await handler(topic, payload)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('mqtt.handler_error', { topic, err })
|
console.error('mqtt.handler_error', { topic, error: formatHandlerError(err) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user