diff --git a/packages/platform-middleware/jwt.ts b/packages/platform-middleware/jwt.ts index d9170356c3..96e7458473 100644 --- a/packages/platform-middleware/jwt.ts +++ b/packages/platform-middleware/jwt.ts @@ -1,4 +1,3 @@ -import { RollupError } from '@proofzero/errors' import { IdentityURNSpace, type IdentityURN } from '@proofzero/urns/identity' import { getAuthzTokenFromReq } from '@proofzero/utils' import { checkToken } from '@proofzero/utils/token' diff --git a/packages/platform-middleware/trace.ts b/packages/platform-middleware/trace.ts index 2d731eff3a..6ec1ddb432 100644 --- a/packages/platform-middleware/trace.ts +++ b/packages/platform-middleware/trace.ts @@ -45,7 +45,7 @@ export class TraceSpan { export const generateTraceSpan = ( headers?: Record | Headers ): TraceSpan => { - let result: TraceSpan + let result: TraceSpan | undefined if (headers) { let traceparent @@ -56,7 +56,7 @@ export const generateTraceSpan = ( if (traceparent) result = createTraceSpan(traceparent as TraceParent) } //If result hasn't been set (due to missing traceparent in header), create new trace - if (!result!) result = createTraceSpan() + if (!result) result = createTraceSpan() return result } @@ -77,21 +77,22 @@ const getTraceParentForSpan = (span: TraceSpan): TraceParent => { const createTraceSpan = (traceparent?: TraceParent): TraceSpan => { const newSpanId = generateRandomString(16) - let result: TraceSpan + let result: TraceSpan | undefined if (traceparent) { const parsedTraceparent = traceparent.split('-') console.assert( parsedTraceparent.length === 4, `traceparent value: ${traceparent}` ) - const [_, traceId, parentId] = parsedTraceparent + const traceId = parsedTraceparent[1] + const parentId = parsedTraceparent[2] if (traceId && parentId) result = new TraceSpan(traceId, newSpanId, parentId) } //If there was no traceparent or the values weren't valid, we create a new one //with no parentId - if (!result!) { + if (!result) { result = new TraceSpan(generateRandomString(32), newSpanId) } return result diff --git a/packages/utils/analytics.ts b/packages/utils/analytics.ts index e6750388be..15cff831be 100644 --- a/packages/utils/analytics.ts +++ b/packages/utils/analytics.ts @@ -7,7 +7,7 @@ export const createAnalyticsEvent = async ({ eventName: string apiKey: string distinctId: string - properties?: Record + properties?: Record }) => { const body = JSON.stringify({ api_key: apiKey, diff --git a/packages/utils/errors.ts b/packages/utils/errors.ts index 0f35655999..1b85938c66 100644 --- a/packages/utils/errors.ts +++ b/packages/utils/errors.ts @@ -46,12 +46,13 @@ export function getRollupReqFunctionErrorWrapper( if (e instanceof Response) return e as Response const error = getErrorCause(e) as Error - const { stack, ...otherProps } = error + delete error.stack + const traceparent = context.traceSpan ? (context.traceSpan as TraceSpan).getTraceParent() : 'No trace information' const result = { - ...otherProps, + ...error, message: error.message, originalError: e, traceparent, diff --git a/platform/object/src/jsonrpc/methods/putObject.ts b/platform/object/src/jsonrpc/methods/putObject.ts index 730cab5b73..b231d97610 100644 --- a/platform/object/src/jsonrpc/methods/putObject.ts +++ b/platform/object/src/jsonrpc/methods/putObject.ts @@ -5,6 +5,7 @@ import { initObjectNodeByName } from '../../nodes' import { Visibility } from '../../types' import { getBaseKey, getObjectKey } from '../../utils' +import { InternalServerError } from '@proofzero/errors' export const PutObjectInput = z.object({ namespace: z.string(), @@ -50,6 +51,11 @@ export const putObjectMethod = async ({ JSON.stringify(value) ) await node.class.set(index.version, index.visibility) + if (!metadata) { + throw new InternalServerError({ + message: 'Metadata is null', + }) + } return { size: metadata.size, version: index.version,