mirror of
https://github.com/unraid/api.git
synced 2026-05-12 18:50:26 -05:00
switch apimanager to singleton, only add apiKey if it exists and move core error handling to correct place
Signed-off-by: Alexis Tyler <xo@wvvw.me>
This commit is contained in:
@@ -11,7 +11,6 @@
|
||||
*/
|
||||
|
||||
module.exports = function ($injector, glob, get, graphql, graphqlDirective, mergeGraphqlSchemas, ApiManager, log, typeDefs, resolvers, loadState, AppError) {
|
||||
const apiManager = new ApiManager();
|
||||
const { buildSchema } = graphql;
|
||||
const { addDirectiveResolveFunctionsToSchema } = graphqlDirective;
|
||||
const { mergeTypes } = mergeGraphqlSchemas;
|
||||
@@ -156,17 +155,19 @@
|
||||
throw new AppError('Missing apikey.');
|
||||
}
|
||||
|
||||
if (apiManager.expired('my_servers')) {
|
||||
if (ApiManager.expired('my_servers')) {
|
||||
try {
|
||||
apiKey = loadState('/boot/config/plugins/dynamix/dynamix.cfg').remote.apikey;
|
||||
} catch (error) {
|
||||
throw new AppError('My servers api key is missing, did you register your server?');
|
||||
}
|
||||
|
||||
apiManager.add('my_servers', apiKey);
|
||||
if (apiKey) {
|
||||
ApiManager.add('my_servers', apiKey);
|
||||
}
|
||||
}
|
||||
|
||||
if (!apiManager.isValid('my_servers', token)) {
|
||||
if (!ApiManager.isValid('my_servers', token)) {
|
||||
throw new AppError('Invalid apikey.');
|
||||
}
|
||||
}
|
||||
|
||||
+13
-11
@@ -64,21 +64,23 @@ am(async () => {
|
||||
const core = $injector.resolve('core');
|
||||
|
||||
// Load core
|
||||
await core.load();
|
||||
await core.load().catch(coreError => {
|
||||
try {
|
||||
// Handler non fatal errors
|
||||
$injector.resolve('globalErrorHandler')(coreError);
|
||||
} catch (error) {
|
||||
throw coreError;
|
||||
}
|
||||
});
|
||||
|
||||
// Load server
|
||||
await core.loadServer('graphql-api');
|
||||
}, error => {
|
||||
try {
|
||||
// Run global error handler
|
||||
$injector.resolve('globalErrorHandler')(error);
|
||||
} catch (error) {
|
||||
// We should only end here if core has an issue loading
|
||||
// We should only end here if core has an issue loading
|
||||
|
||||
// Log last error
|
||||
console.error(error);
|
||||
// Log last error
|
||||
console.error(error);
|
||||
|
||||
// Kill applicaiton
|
||||
process.exit(1);
|
||||
}
|
||||
// Kill applicaiton
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user