Skip to content

Commit 6dd485a

Browse files
authored
Merge pull request #393 from the-hideout/graphql-errors
Graphql errors
2 parents 45f94b2 + 8e5c3a8 commit 6dd485a

14 files changed

+59
-31
lines changed

datasources/archived-prices.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { GraphQLError } from 'graphql';
2+
13
import WorkerKVSplit from '../utils/worker-kv-split.mjs';
24

35
class ArchivedPricesAPI extends WorkerKVSplit {
@@ -9,7 +11,7 @@ class ArchivedPricesAPI extends WorkerKVSplit {
911
async getByItemId(context, info, itemId) {
1012
const { cache } = await this.getCache(context, info, itemId);
1113
if (!cache) {
12-
return Promise.reject(new Error('Archived prices data is empty'));
14+
return Promise.reject(new GraphQLError('Archived prices data is empty'));
1315
}
1416

1517
let prices = cache.ArchivedPrices[itemId];

datasources/handbook.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { GraphQLError } from 'graphql';
2+
13
import WorkerKV from '../utils/worker-kv.mjs';
24

35
class HandbookAPI extends WorkerKV {
@@ -20,7 +22,7 @@ class HandbookAPI extends WorkerKV {
2022
async getCategories(context, info) {
2123
const { cache } = await this.getCache(context, info);
2224
if (!cache) {
23-
return Promise.reject(new Error('Item cache is empty'));
25+
return Promise.reject(new GraphQLError('Item cache is empty'));
2426
}
2527
const categories = [];
2628
for (const id in cache.ItemCategory) {
@@ -46,7 +48,7 @@ class HandbookAPI extends WorkerKV {
4648
async getHandbookCategories(context, info) {
4749
const { cache } = await this.getCache(context, info);
4850
if (!cache) {
49-
return Promise.reject(new Error('Item cache is empty'));
51+
return Promise.reject(new GraphQLError('Item cache is empty'));
5052
}
5153
return Object.values(cache.HandbookCategory);
5254
}

datasources/hideout.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { GraphQLError } from 'graphql';
2+
13
import WorkerKV from '../utils/worker-kv.mjs';
24

35
class HideoutAPI extends WorkerKV {
@@ -20,7 +22,7 @@ class HideoutAPI extends WorkerKV {
2022
}
2123
}
2224
}
23-
return Promise.reject(new Error(`No hideout station level found with id ${id}`));
25+
return Promise.reject(new GraphQLError(`No hideout station level found with id ${id}`));
2426
}
2527

2628
async getModuleByLevel(context, info, stationId, level) {
@@ -33,15 +35,15 @@ class HideoutAPI extends WorkerKV {
3335
}
3436
}
3537
}
36-
return Promise.reject(new Error(`No hideout station level found with id ${stationId} and level ${level}`));
38+
return Promise.reject(new GraphQLError(`No hideout station level found with id ${stationId} and level ${level}`));
3739
}
3840

3941
async getStation(context, info, id) {
4042
const { cache } = await this.getCache(context, info);
4143
for (const station of cache.HideoutStation) {
4244
if (station.id === id) return station;
4345
}
44-
return Promise.reject(new Error(`No hideout station found with id ${id}`));
46+
return Promise.reject(new GraphQLError(`No hideout station found with id ${id}`));
4547
}
4648

4749
async getLegacyList(context, info) {
@@ -56,7 +58,7 @@ class HideoutAPI extends WorkerKV {
5658
return module;
5759
}
5860
}
59-
return Promise.reject(new Error(`No hideout module with id ${id} found`));
61+
return Promise.reject(new GraphQLError(`No hideout module with id ${id} found`));
6062
}
6163
}
6264

datasources/historical-prices.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { GraphQLError } from 'graphql';
2+
13
import WorkerKVSplit from '../utils/worker-kv-split.mjs';
24

35
class historicalPricesAPI extends WorkerKVSplit {
@@ -12,7 +14,7 @@ class historicalPricesAPI extends WorkerKVSplit {
1214
async getByItemId(context, info, itemId, days = this.defaultDays, halfResults = false) {
1315
const { cache } = await this.getCache(context, info, itemId);
1416
if (!cache) {
15-
return Promise.reject(new Error('Historical prices cache is empty'));
17+
return Promise.reject(new GraphQLError('Historical prices cache is empty'));
1618
}
1719

1820
if (days > this.maxDays || days < 1) {

datasources/items.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { GraphQLError } from 'graphql';
2+
13
import WorkerKV from '../utils/worker-kv.mjs';
24

35
class ItemsAPI extends WorkerKV {
@@ -63,7 +65,7 @@ class ItemsAPI extends WorkerKV {
6365
const { cache } = await this.getCache(context, info);
6466
let item = cache.Item[id];
6567
if (!item) {
66-
return Promise.reject(new Error(`No item found with id ${id}`));
68+
return Promise.reject(new GraphQLError(`No item found with id ${id}`));
6769
}
6870

6971
if (contains && Array.isArray(contains)) {
@@ -114,7 +116,7 @@ class ItemsAPI extends WorkerKV {
114116
items = Object.values(cache.Item);
115117
}
116118
const searchString = name.toLowerCase();
117-
if (searchString === '') return Promise.reject(new Error('Searched item name cannot be blank'));
119+
if (searchString === '') return Promise.reject(new GraphQLError('Searched item name cannot be blank'));
118120

119121
return items.filter((item) => {
120122
if (this.getLocale(item.name, context, info).toString().toLowerCase().includes(searchString)) {
@@ -133,7 +135,7 @@ class ItemsAPI extends WorkerKV {
133135
items = Object.values(cache.Item);
134136
}
135137
const searchStrings = names.map(name => {
136-
if (name === '') throw new Error('Searched item name cannot be blank');
138+
if (name === '') throw new GraphQLError('Searched item name cannot be blank');
137139
return name.toLowerCase();
138140
});
139141
return items.filter((item) => {

datasources/maps.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { GraphQLError } from 'graphql';
2+
13
import WorkerKV from '../utils/worker-kv.mjs';
24

35
class MapAPI extends WorkerKV {
@@ -16,7 +18,7 @@ class MapAPI extends WorkerKV {
1618
for (const map of cache.Map) {
1719
if (map.id === id || map.tarkovDataId === id) return map;
1820
}
19-
return Promise.reject(new Error(`No map found with id ${id}`));
21+
return Promise.reject(new GraphQLError(`No map found with id ${id}`));
2022
}
2123

2224
async getMapsByNames(context, info, names, maps = false) {
@@ -25,7 +27,7 @@ class MapAPI extends WorkerKV {
2527
maps = cache.Map;
2628
}
2729
const searchStrings = names.map(name => {
28-
if (name === '') throw new Error('Searched map name cannot be blank');
30+
if (name === '') throw new GraphQLError('Searched map name cannot be blank');
2931
return name.toLowerCase();
3032
});
3133

@@ -45,7 +47,7 @@ class MapAPI extends WorkerKV {
4547
maps = cache.Map;
4648
}
4749
const searchStrings = enemies.map(name => {
48-
if (name === '') throw new Error('Searched enemy name cannot be blank');
50+
if (name === '') throw new GraphQLError('Searched enemy name cannot be blank');
4951
return name.toLowerCase();
5052
});
5153

@@ -76,7 +78,7 @@ class MapAPI extends WorkerKV {
7678
bosses = Object.values(cache.MobInfo);
7779
}
7880
const searchStrings = names.map(name => {
79-
if (name === '') throw new Error('Searched boss name cannot be blank');
81+
if (name === '') throw new GraphQLError('Searched boss name cannot be blank');
8082
return name.toLowerCase();
8183
});
8284

datasources/schema.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { GraphQLError } from 'graphql';
2+
13
import WorkerKV from '../utils/worker-kv.mjs';
24

35
class SchemaAPI extends WorkerKV {
@@ -8,31 +10,31 @@ class SchemaAPI extends WorkerKV {
810
async getCategories(context) {
911
const { cache } = await this.getCache(context);
1012
if (!cache) {
11-
return Promise.reject(new Error('Schema cache is empty'));
13+
return Promise.reject(new GraphQLError('Schema cache is empty'));
1214
}
1315
return cache.ItemCategory;
1416
}
1517

1618
async getHandbookCategories(context) {
1719
const { cache } = await this.getCache(context);
1820
if (!cache) {
19-
return Promise.reject(new Error('Schema cache is empty'));
21+
return Promise.reject(new GraphQLError('Schema cache is empty'));
2022
}
2123
return cache.HandbookCategory;
2224
}
2325

2426
async getItemTypes(context) {
2527
const { cache } = await this.getCache(context);
2628
if (!cache) {
27-
return Promise.reject(new Error('Schema cache is empty'));
29+
return Promise.reject(new GraphQLError('Schema cache is empty'));
2830
}
2931
return cache.ItemType;
3032
}
3133

3234
async getLanguageCodes(context) {
3335
const { cache } = await this.getCache(context);
3436
if (!cache) {
35-
return Promise.reject(new Error('Schema cache is empty'));
37+
return Promise.reject(new GraphQLError('Schema cache is empty'));
3638
}
3739
return cache.LanguageCode;
3840
}

datasources/status.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { GraphQLError } from 'graphql';
2+
13
import WorkerKV from '../utils/worker-kv.mjs';
24

35
class StatusAPI extends WorkerKV {
@@ -8,7 +10,7 @@ class StatusAPI extends WorkerKV {
810
async getStatus(context) {
911
const { cache } = await this.getCache(context);
1012
if (!cache) {
11-
return Promise.reject(new Error('Status cache is empty'));
13+
return Promise.reject(new GraphQLError('Status cache is empty'));
1214
}
1315
return cache.ServerStatus;
1416
}

datasources/tasks.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { GraphQLError } from 'graphql';
2+
13
import WorkerKV from '../utils/worker-kv.mjs';
24

35
class TasksAPI extends WorkerKV {
@@ -16,7 +18,7 @@ class TasksAPI extends WorkerKV {
1618
for (const task of cache.Task) {
1719
if (task.id === id || task.tarkovDataId === id) return task;
1820
}
19-
return Promise.reject(new Error(`No task found with id ${id}`));
21+
return Promise.reject(new GraphQLError(`No task found with id ${id}`));
2022
}
2123

2224
async getTasksRequiringItem(context, info, itemId) {
@@ -114,7 +116,7 @@ class TasksAPI extends WorkerKV {
114116
return quest;
115117
}
116118
}
117-
return Promise.reject(new Error(`No quest with id ${id} found`));
119+
return Promise.reject(new GraphQLError(`No quest with id ${id} found`));
118120
}
119121

120122
async getQuestItems(context, info) {
@@ -139,7 +141,7 @@ class TasksAPI extends WorkerKV {
139141
return achievement;
140142
}
141143
}
142-
return Promise.reject(new Error(`No achievement with id ${id} found`));
144+
return Promise.reject(new GraphQLError(`No achievement with id ${id} found`));
143145
}
144146
}
145147

datasources/traders.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { GraphQLError } from 'graphql';
2+
13
import WorkerKV from '../utils/worker-kv.mjs';
24

35
const currencyMap = {
@@ -55,7 +57,7 @@ class TradersAPI extends WorkerKV {
5557
}
5658
}
5759

58-
return Promise.reject(new Error(`No trader found with id ${id}`));
60+
return Promise.reject(new GraphQLError(`No trader found with id ${id}`));
5961
}
6062

6163
async getByName(context, info, name) {
@@ -66,7 +68,7 @@ class TradersAPI extends WorkerKV {
6668
}
6769
}
6870

69-
return Promise.reject(new Error(`No trader found with name ${name}`));
71+
return Promise.reject(new GraphQLError(`No trader found with name ${name}`));
7072
}
7173

7274
async getByLevel(context, info, traderId, level) {
@@ -79,7 +81,7 @@ class TradersAPI extends WorkerKV {
7981
}
8082
}
8183
}
82-
return Promise.reject(new Error(`No trader found with id ${traderId} and level ${level}`));
84+
return Promise.reject(new GraphQLError(`No trader found with id ${traderId} and level ${level}`));
8385
}
8486

8587
getByDataId(context, info, dataId) {

0 commit comments

Comments
 (0)