Skip to content

Conversation

jona159
Copy link
Contributor

@jona159 jona159 commented Sep 25, 2025

No description provided.

@mashazyu
Copy link
Contributor

@jona159 , per our conversation I am adding summary of our discussion.

I tested data upload presented in this PR via senseBox:bike app.

  1. First, I got the following error message:

error 422: {"code":"UnprocessableEntity","message":"Cannot read properties of undefined (reading 'decodeMessage')"}

Cursor suggested the following fix, that worked for me locally

Issue:

Measurement upload failing with: "Cannot read properties of undefined (reading 'decodeMessage')"

Root Cause:

The decoder lookup was failing when content-type included charset (e.g., "application/json; charset=utf-8")

Fix:

Modified one file: app/lib/decoding-service.server.ts

Added a normalization function and updated the decoder lookup:

// NEW: Normalize content type to match decoder keys

function normalizeContentType(contentType: string): string {

  const normalized \= contentType.toLowerCase().split(';')[0].trim();

  if (normalized.includes('json')) return 'application/json';

  if (normalized.includes('csv')) return 'text/csv';

  if (normalized \=== 'application/sbx-bytes-ts') return 'application/sbx-bytes-ts';

  if (normalized \=== 'application/sbx-bytes') return 'application/sbx-bytes';

  return normalized;

}

// UPDATED: Use normalized content-type for decoder lookup

export async function decodeMeasurements(

  measurements: any,

  options: { contentType: string; sensors: any[] }

): Promise<any[]> {

  try {

const normalizedContentType \= normalizeContentType(options.contentType); // ADDED

const handler \= decodeHandlers\[normalizedContentType\]; // CHANGED

if (!handler) { // ADDED null check

  throw new Error(\`No decoder found for content-type: ${options.contentType}\`);

}

return handler.decodeMessage(measurements, { sensors: options.sensors });
  } catch (err: any) {

const error \= new Error(err.message);

error.name \= "ModelError";

(error as any).type \= "UnprocessableEntityError";

throw error;
  }
}
  1. After applying the fix I was able to "bulk upload" track data from app. I verified that data stored in local database matched track data stored in the app. In other words, I believe data is stored correctly.

Please let me know, if any furhter testing is needed.

@jona159 jona159 marked this pull request as ready for review October 15, 2025 07:29
@jona159 jona159 linked an issue Oct 15, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

migrate /boxes/:boxId/data & /boxes/:boxId/:sensorId

2 participants