Skip to content

Commit

Permalink
fixes error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanpedersen committed Jul 12, 2017
1 parent 72cef14 commit f506738
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
9 changes: 5 additions & 4 deletions packages/nocms/lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ function createServer({ resolveOutputPath, resourceProvider, commandSender, port
const resource = resources.find(function (resource) {
return resource.id === resourceId;
});

if (!resource) {
throw new Error('Resource Not Found');
}

const variant = parseInt(req.query.variant) || 0;
let outFile = resource.outFile;

Expand All @@ -44,10 +49,6 @@ function createServer({ resolveOutputPath, resourceProvider, commandSender, port
outFile = parts.filter(Boolean).join('.');
}

if (!resource) {
throw new Error('Resource Not Found');
}

yield commandSender.sendCommand({
id: ++count,
name: 'compileResource',
Expand Down
11 changes: 6 additions & 5 deletions packages/nocms/src/lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export function createServer ({resolveOutputPath, resourceProvider, commandSende
const resourceId = url.parse(req.url).pathname;
const resources = await resourceProvider.getResources();
const resource = resources.find(resource => resource.id === resourceId);

if (!resource) {
throw new Error('Resource Not Found');
}

const variant = parseInt(req.query.variant) || 0;
let outFile = resource.outFile;

Expand All @@ -23,11 +28,7 @@ export function createServer ({resolveOutputPath, resourceProvider, commandSende
parts.splice(-1, 0, variant);
outFile = parts.filter(Boolean).join('.');
}

if (!resource) {
throw new Error('Resource Not Found');
}


await commandSender.sendCommand({
id: ++count,
name: 'compileResource',
Expand Down

0 comments on commit f506738

Please sign in to comment.