Skip to content

Commit

Permalink
feat: detail
Browse files Browse the repository at this point in the history
  • Loading branch information
cool-firer committed Oct 11, 2024
1 parent 58eb0f2 commit 4c0d8b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
10 changes: 6 additions & 4 deletions packages/network-support/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export function createFetch(
deploymentId: orderManager.getProjectId(),
indexer: runner,
requestId,
fallbackServiceUrl: orderManager.fallbackServiceUrl,
retry: retries,
rid,
});
Expand Down Expand Up @@ -132,7 +133,7 @@ export function createFetch(
await _res.text(),
new Headers(_res.headers),
channelId,
requestId
{ requestId, deploymentId: orderManager.getProjectId(), indexer: runner }
);
}
if (type === OrderType.agreement) {
Expand All @@ -145,7 +146,7 @@ export function createFetch(
}
if (type === OrderType.fallback) {
logger?.info({
type: 'fallback',
type: 'res_fallback',
deploymentId: orderManager.getProjectId(),
indexer: runner,
requestId,
Expand All @@ -166,7 +167,7 @@ export function createFetch(

if (_res.status !== 200 && type === OrderType.fallback) {
logger?.info({
type: 'fallbackDetail',
type: 'detail_fallback',
deploymentId: orderManager.getProjectId(),
status: _res.status,
retry: retries,
Expand Down Expand Up @@ -209,6 +210,7 @@ export function createFetch(
requestId,
retry: retries,
error: errorMsg,
stack: e.stack,
};

orderManager.updateScore(runner, scoreType, 0, extraLog);
Expand All @@ -233,7 +235,7 @@ export function createFetch(
}

logger?.error({
type: 'throwOut',
type: type === OrderType.fallback ? 'error_fallback' : 'throwOut',
deploymentId: orderManager.getProjectId(),
indexer: runner,
requestId,
Expand Down
31 changes: 22 additions & 9 deletions packages/network-support/src/orderManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ import {
ServiceAgreementOrder,
WrappedResponse,
} from './types';
import { createMemoryStore, fetchOrders, isTokenExpired, IStore, Logger, POST } from './utils';
import {
createMemoryStore,
fetchOrders,
isTokenExpired,
IStore,
Logger,
POST,
safeJSONParse,
} from './utils';
import { BlockType, State, StateManager } from './stateManager';
import { Version } from './utils/version';
import { NotifyFunc } from './types';
Expand Down Expand Up @@ -266,7 +274,7 @@ export class OrderManager {
payload: string | object,
headers: Headers,
channelId?: string,
requestId?: string
logData?: any
): [object, State | ChannelState, string] {
switch (headers.get('X-Indexer-Response-Format')) {
case ResponseFormat.Wrapped: {
Expand All @@ -291,29 +299,34 @@ export class OrderManager {
if (channelId) this.syncChannelState(channelId, state);
const _signature = headers.get('X-Indexer-Sig') || '';
// assert(_signature, 'invalid response, missing channel signature');
this.logger?.info({
type: 'inline',
requestId,
data: payload,
});
if (!safeJSONParse(payload as string)) {
logData = logData || {};
this.logger?.info({
type: 'inline',
data: payload,
...logData,
});
}
return [typeof payload === 'string' ? JSON.parse(payload) : payload, state, _signature];
}
case undefined: {
logData = logData || {};
this.logger?.info({
type: 'headerUndef',
requestId,
data: payload,
...logData,
});
const body = typeof payload === 'string' ? JSON.parse(payload) : payload;
const state = body.state;
if (channelId) this.syncChannelState(channelId, state);
return [body, state, ''];
}
default:
logData = logData || {};
this.logger?.info({
type: 'headerNull',
requestId,
data: payload,
...logData,
});
if (typeof payload === 'string') {
payload = JSON.parse(payload);
Expand Down

0 comments on commit 4c0d8b8

Please sign in to comment.