Skip to content

Commit

Permalink
feat: improve error handling on missing controller & serializer files (
Browse files Browse the repository at this point in the history
…#118)

We now have the following messages when a file is missing

```
Error: Could not resolve model by name 'user'
Error: Could not resolve controller by name 'users'
Error: Could not resolve serializer by name 'users'
```

Fixes #104
  • Loading branch information
neojp authored and zacharygolba committed May 21, 2016
1 parent 1dd3ab6 commit a7f1910
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/packages/application/errors/controller-missing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ControllerMissingError extends Error {
constructor(resource) {
return super(`Could not resolve controller by name '${resource}'`);
}
}

export default ControllerMissingError;
2 changes: 2 additions & 0 deletions src/packages/application/errors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export ControllerMissingError from './controller-missing';
export SerializerMissingError from './serializer-missing';
7 changes: 7 additions & 0 deletions src/packages/application/errors/serializer-missing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class SerializerMissingError extends Error {
constructor(resource) {
return super(`Could not resolve serializer by name '${resource}'`);
}
}

export default SerializerMissingError;
19 changes: 18 additions & 1 deletion src/packages/application/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import Promise from 'bluebird';
import cluster from 'cluster';
import { singularize } from 'inflection';
import { pluralize, singularize } from 'inflection';

import Server from '../server';
import Router from '../router';
import Database from '../database';

import loader from '../loader';

import {
ControllerMissingError,
SerializerMissingError
} from './errors';

const { defineProperties } = Object;

const { env: { PWD, PORT } } = process;
Expand Down Expand Up @@ -115,6 +120,18 @@ class Application {

await store.define(models);

models.forEach((model, name) => {
const resource = pluralize(name);

if (!controllers.get(resource)) {
throw new ControllerMissingError(resource);
}

if (!serializers.get(resource)) {
throw new SerializerMissingError(resource);
}
});

serializers.forEach((serializer, name) => {
const model = models.get(singularize(name));

Expand Down

0 comments on commit a7f1910

Please sign in to comment.