Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] DTL response null result with 404 http status DEMO code #1389

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions packages/data-transport-layer/src/services/server/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { JsonRpcProvider } from '@ethersproject/providers'
import { LevelUp } from 'levelup'
import * as Sentry from '@sentry/node'
import * as Tracing from '@sentry/tracing'
import {HttpCodes} from "../../utils";

/* Imports: Internal */

Expand Down Expand Up @@ -237,7 +238,13 @@ export class L1TransportServer extends BaseService<L1TransportServerOptions> {
this.state.app[method](route, async (req, res) => {
const start = Date.now()
try {
const json = await handler(req, res)
let httpCode = HttpCodes.OK, json;
const result = await handler(req, res)
if(Array.isArray(result)) {
[json, httpCode] = result;
} else {
json = result;
}
const elapsed = Date.now() - start
this.logger.info('Served HTTP Request', {
method: req.method,
Expand All @@ -249,7 +256,7 @@ export class L1TransportServer extends BaseService<L1TransportServerOptions> {
url: req.url,
body: json,
})
return res.json(json)
return res.status(httpCode).json(json)
} catch (e) {
const elapsed = Date.now() - start
this.logger.error('Failed HTTP Request', {
Expand Down Expand Up @@ -498,7 +505,7 @@ export class L1TransportServer extends BaseService<L1TransportServerOptions> {
this._registerRoute(
'get',
'/transaction/index/:index',
async (req): Promise<TransactionResponse> => {
async (req): Promise<[TransactionResponse, HttpCodes]> => {
const backend = req.query.backend || this.options.defaultBackend
let transaction = null

Expand All @@ -518,20 +525,20 @@ export class L1TransportServer extends BaseService<L1TransportServerOptions> {
}

if (transaction === null) {
return {
return [{
transaction: null,
batch: null,
}
}, HttpCodes.NOT_FOUND]
}

const batch = await this.state.db.getTransactionBatchByIndex(
transaction.batchIndex
)

return {
return [{
transaction,
batch,
}
}, HttpCodes.OK]
}
)

Expand Down
Loading
Loading