Skip to content

Commit

Permalink
fix: change error results and other minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Jul 17, 2023
1 parent e4acd0f commit 6203b99
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
9 changes: 4 additions & 5 deletions services/api/src/resources/task/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Sql } from './sql';
import { Sql as projectSql } from '../project/sql';
import { Sql as environmentSql } from '../environment/sql';
import { Helpers as environmentHelpers } from '../environment/helpers';
// import convertDateToMYSQLDateTimeFormat from '../../util/convertDateToMYSQLDateTimeFormat';

export const Helpers = (sqlClientPool: Pool, hasPermission) => {
const getTaskById = async (TaskID: number) => {
Expand Down Expand Up @@ -257,7 +256,7 @@ export const Helpers = (sqlClientPool: Pool, hasPermission) => {
getTaskById,
task => {
if (!task) {
throw new Error('Unauthorized');
throw new Error('No matching task found');
}

return task;
Expand All @@ -273,8 +272,8 @@ export const Helpers = (sqlClientPool: Pool, hasPermission) => {
environments
);

if (activeEnvironments.length < 1 || activeEnvironments.length > 1) {
throw new Error('Unauthorized');
if (activeEnvironments.length != 1) {
throw new Error('No matching environment found');
}

const environment = R.prop(0, activeEnvironments);
Expand All @@ -288,7 +287,7 @@ export const Helpers = (sqlClientPool: Pool, hasPermission) => {
);

if (!R.prop(0, rows)) {
throw new Error('Unauthorized');
throw new Error('No matching task found');
}

return R.prop(0, rows);
Expand Down
6 changes: 1 addition & 5 deletions services/api/src/resources/task/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { Validators as envValidators } from '../environment/validators';
import S3 from 'aws-sdk/clients/s3';
import sha1 from 'sha1';
import { generateTaskName } from '@lagoon/commons/dist/util/lagoon';
// import { logger } from '../../loggers/logger';
import { sendToLagoonLogs } from '@lagoon/commons/dist/logs/lagoon-logger';
import { createMiscTask } from '@lagoon/commons/dist/tasks';

Expand Down Expand Up @@ -349,10 +348,7 @@ export const cancelTask: ResolverFn = async (
return null;
}

const envPerm = await environmentHelpers(sqlClientPool).getEnvironmentById(
task.environment
);
await hasPermission('task', `cancel:${envPerm.environmentType}`, {
await hasPermission('task', `cancel:${environment.environmentType}`, {
project: project.id
});

Expand Down

0 comments on commit 6203b99

Please sign in to comment.