Skip to content

Commit

Permalink
Restored some things lost by merge
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonVanneste committed Feb 8, 2019
1 parent a3d1af6 commit 42d365a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/errors/LocationResolverError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default class LocationResolverError extends Error {

}
9 changes: 6 additions & 3 deletions src/query-runner/LocationResolverDefault.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { inject, injectable } from "inversify";
import LocationResolverError from "../errors/LocationResolverError";
import IStop from "../fetcher/stops/IStop";
import IStopsProvider from "../fetcher/stops/IStopsProvider";
import ILocation from "../interfaces/ILocation";
Expand Down Expand Up @@ -30,7 +31,7 @@ export default class LocationResolverDefault implements ILocationResolver {
return this.resolveById(input);
}

return Promise.reject(`Location "${input}" is a string, but not an ID`);
return Promise.reject(new LocationResolverError(`Location "${input}" is a string, but not an ID`));
}

const location: ILocation = input;
Expand All @@ -44,7 +45,9 @@ export default class LocationResolverDefault implements ILocationResolver {
}

if (!hasCoords) {
return Promise.reject(`Location "${JSON.stringify(input)}" should have latitude and longitude`);
return Promise.reject(
new LocationResolverError(`Location "${JSON.stringify(input)}" should have latitude and longitude`),
);
}

return location;
Expand All @@ -62,7 +65,7 @@ export default class LocationResolverDefault implements ILocationResolver {
};
}

throw new Error(`No fetcher for id ${id}`);
return Promise.reject(new LocationResolverError(`No fetcher for id ${id}`));
}

private isId(testString: string): boolean {
Expand Down
14 changes: 11 additions & 3 deletions src/query-runner/QueryRunnerDefault.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { AsyncIterator } from "asynciterator";
import { inject, injectable } from "inversify";
import { cat } from "shelljs";
import Defaults from "../Defaults";
import InvalidQueryError from "../errors/InvalidQueryError";
import ILocation from "../interfaces/ILocation";
import IPath from "../interfaces/IPath";
import IQuery from "../interfaces/IQuery";
Expand Down Expand Up @@ -37,7 +39,7 @@ export default class QueryRunnerDefault implements IQueryRunner {
return this.publicTransportPlanner.plan(resolvedQuery);

} else {
return Promise.reject("Query not supported");
throw new InvalidQueryError("Query should have publicTransportOnly = true");
}
}

Expand Down Expand Up @@ -83,8 +85,14 @@ export default class QueryRunnerDefault implements IQueryRunner {
resolvedQuery.maximumArrivalTime = newMaximumArrivalTime;
}

resolvedQuery.from = await this.resolveEndpoint(from);
resolvedQuery.to = await this.resolveEndpoint(to);
try {
resolvedQuery.from = await this.resolveEndpoint(from);
resolvedQuery.to = await this.resolveEndpoint(to);

} catch (e) {
return Promise.reject(new InvalidQueryError(e));
}

resolvedQuery.minimumWalkingSpeed = minimumWalkingSpeed || walkingSpeed || Defaults.defaultMinimumWalkingSpeed;
resolvedQuery.maximumWalkingSpeed = maximumWalkingSpeed || walkingSpeed || Defaults.defaultMaximumWalkingSpeed;

Expand Down

0 comments on commit 42d365a

Please sign in to comment.