@@ -154,22 +154,17 @@ export function setupRoutes(app: Express, ddbApi: DynamoDbApi): void {
154154 }
155155 }
156156
157- try {
158- await ddbApi . createTable ( {
159- TableName,
160- ProvisionedThroughput : {
161- ReadCapacityUnits,
162- WriteCapacityUnits,
163- } ,
164- GlobalSecondaryIndexes : globalSecondaryIndexes . length ? globalSecondaryIndexes : undefined ,
165- LocalSecondaryIndexes : localSecondaryIndexes . length ? localSecondaryIndexes : undefined ,
166- KeySchema : keySchema ,
167- AttributeDefinitions : attributeDefinitions ,
168- } ) ;
169- } catch ( error ) {
170- res . status ( 400 ) . send ( error ) ;
171- return ;
172- }
157+ await ddbApi . createTable ( {
158+ TableName,
159+ ProvisionedThroughput : {
160+ ReadCapacityUnits,
161+ WriteCapacityUnits,
162+ } ,
163+ GlobalSecondaryIndexes : globalSecondaryIndexes . length ? globalSecondaryIndexes : undefined ,
164+ LocalSecondaryIndexes : localSecondaryIndexes . length ? localSecondaryIndexes : undefined ,
165+ KeySchema : keySchema ,
166+ AttributeDefinitions : attributeDefinitions ,
167+ } ) ;
173168
174169 res . status ( 204 ) . end ( ) ;
175170 } ) ,
@@ -327,39 +322,34 @@ export function setupRoutes(app: Express, ddbApi: DynamoDbApi): void {
327322 } ;
328323 const pageSize = typeof req . query . pageSize === 'string' ? Number . parseInt ( req . query . pageSize ) : 25 ;
329324
330- try {
331- const results = await getPage ( ddbApi , tableDescription . KeySchema ! , TableName , params , pageSize , operationType ) ;
332- const { pageItems, nextKey } = results ;
325+ const results = await getPage ( ddbApi , tableDescription . KeySchema ! , TableName , params , pageSize , operationType ) ;
326+ const { pageItems, nextKey } = results ;
333327
334- const primaryKeys = tableDescription . KeySchema ! . map ( schema => schema . AttributeName ) ;
335- // Primary keys are listed first.
336- const uniqueKeys = [
337- ...primaryKeys ,
338- ...extractKeysForItems ( pageItems ) . filter ( key => ! primaryKeys . includes ( key ) ) ,
339- ] ;
328+ const primaryKeys = tableDescription . KeySchema ! . map ( schema => schema . AttributeName ) ;
329+ // Primary keys are listed first.
330+ const uniqueKeys = [
331+ ...primaryKeys ,
332+ ...extractKeysForItems ( pageItems ) . filter ( key => ! primaryKeys . includes ( key ) ) ,
333+ ] ;
340334
341- // Append the item key.
342- for ( const item of pageItems ) {
343- item . __key = extractKey ( item , tableDescription . KeySchema ! ) ;
344- }
335+ // Append the item key.
336+ for ( const item of pageItems ) {
337+ item . __key = extractKey ( item , tableDescription . KeySchema ! ) ;
338+ }
345339
346- const data = {
347- query : req . query ,
348- pageNum,
349- prevKey : encodeURIComponent ( typeof req . query . prevKey === 'string' ? req . query . prevKey : '' ) ,
350- startKey : encodeURIComponent ( typeof req . query . startKey === 'string' ? req . query . startKey : '' ) ,
351- nextKey : nextKey ? encodeURIComponent ( JSON . stringify ( nextKey ) ) : null ,
352- filterQueryString : encodeURIComponent ( typeof req . query . filters === 'string' ? req . query . filters : '' ) ,
353- Table : tableDescription ,
354- Items : pageItems ,
355- uniqueKeys,
356- } ;
340+ const data = {
341+ query : req . query ,
342+ pageNum,
343+ prevKey : encodeURIComponent ( typeof req . query . prevKey === 'string' ? req . query . prevKey : '' ) ,
344+ startKey : encodeURIComponent ( typeof req . query . startKey === 'string' ? req . query . startKey : '' ) ,
345+ nextKey : nextKey ? encodeURIComponent ( JSON . stringify ( nextKey ) ) : null ,
346+ filterQueryString : encodeURIComponent ( typeof req . query . filters === 'string' ? req . query . filters : '' ) ,
347+ Table : tableDescription ,
348+ Items : pageItems ,
349+ uniqueKeys,
350+ } ;
357351
358- res . json ( data ) ;
359- } catch ( error : any ) {
360- const typedError : Error & { code ?: number } = error ;
361- res . status ( 400 ) . send ( ( typedError . code ? '[' + typedError . code + '] ' : '' ) + typedError . message ) ;
362- }
352+ res . json ( data ) ;
363353 } ) ) ;
364354
365355 app . get ( '/tables/:TableName/meta' , asyncMiddleware ( async ( req , res ) => {
@@ -453,8 +443,7 @@ export function setupRoutes(app: Express, ddbApi: DynamoDbApi): void {
453443 res . json ( response . Item ) ;
454444 } ) ) ;
455445
456- app . use ( ( ( err , _req , _res , next ) => {
457- console . error ( err ) ;
458- next ( err ) ;
446+ app . use ( ( ( error , _req , res , _next ) => {
447+ res . status ( 500 ) . send ( error ) ;
459448 } ) as ErrorRequestHandler ) ;
460449}
0 commit comments