Better async error handling
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import gunzip from 'gunzip-maybe';
|
||||
import tar from 'tar-stream';
|
||||
|
||||
import asyncHandler from '../utils/asyncHandler.js';
|
||||
import bufferStream from '../utils/bufferStream.js';
|
||||
import getContentType from '../utils/getContentType.js';
|
||||
import getIntegrity from '../utils/getIntegrity.js';
|
||||
@ -32,16 +33,20 @@ async function findEntry(stream, filename) {
|
||||
return;
|
||||
}
|
||||
|
||||
const content = await bufferStream(stream);
|
||||
try {
|
||||
const content = await bufferStream(stream);
|
||||
|
||||
entry.contentType = getContentType(entry.path);
|
||||
entry.integrity = getIntegrity(content);
|
||||
entry.lastModified = header.mtime.toUTCString();
|
||||
entry.size = content.length;
|
||||
entry.contentType = getContentType(entry.path);
|
||||
entry.integrity = getIntegrity(content);
|
||||
entry.lastModified = header.mtime.toUTCString();
|
||||
entry.size = content.length;
|
||||
|
||||
foundEntry = entry;
|
||||
foundEntry = entry;
|
||||
|
||||
next();
|
||||
next();
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
})
|
||||
.on('finish', () => {
|
||||
accept(foundEntry);
|
||||
@ -49,7 +54,7 @@ async function findEntry(stream, filename) {
|
||||
});
|
||||
}
|
||||
|
||||
export default async function serveFileMetadata(req, res) {
|
||||
async function serveFileMetadata(req, res) {
|
||||
const stream = await getPackage(req.packageName, req.packageVersion);
|
||||
const entry = await findEntry(stream, req.filename);
|
||||
|
||||
@ -59,3 +64,5 @@ export default async function serveFileMetadata(req, res) {
|
||||
|
||||
res.send(entry);
|
||||
}
|
||||
|
||||
export default asyncHandler(serveFileMetadata);
|
||||
|
Reference in New Issue
Block a user