Error cleanup

#11 #13 #14
This commit is contained in:
Nicolai Ort 2020-12-05 19:01:30 +01:00
parent 21ad622c10
commit 1ae466a6f4
11 changed files with 49 additions and 42 deletions

View File

@ -2,7 +2,8 @@ import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, Query
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { getConnectionManager, Repository } from 'typeorm'; import { getConnectionManager, Repository } from 'typeorm';
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions'; import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
import { RunnerGroupNeededError, RunnerGroupNotFoundError, RunnerIdsNotMatchingError, RunnerNotFoundError, RunnerOnlyOneGroupAllowedError } from '../errors/RunnerErrors'; import { RunnerGroupNeededError, RunnerIdsNotMatchingError, RunnerNotFoundError } from '../errors/RunnerErrors';
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
import { CreateRunner } from '../models/actions/CreateRunner'; import { CreateRunner } from '../models/actions/CreateRunner';
import { Runner } from '../models/entities/Runner'; import { Runner } from '../models/entities/Runner';
import { ResponseRunner } from '../models/responses/ResponseRunner'; import { ResponseRunner } from '../models/responses/ResponseRunner';
@ -43,7 +44,6 @@ export class RunnerController {
@Post() @Post()
@ResponseSchema(ResponseRunner) @ResponseSchema(ResponseRunner)
@ResponseSchema(RunnerOnlyOneGroupAllowedError)
@ResponseSchema(RunnerGroupNeededError) @ResponseSchema(RunnerGroupNeededError)
@ResponseSchema(RunnerGroupNotFoundError) @ResponseSchema(RunnerGroupNotFoundError)
@OpenAPI({ description: 'Create a new runner object (id will be generated automagicly).' }) @OpenAPI({ description: 'Create a new runner object (id will be generated automagicly).' })

View File

@ -2,7 +2,8 @@ import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put } from
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { getConnectionManager, Repository } from 'typeorm'; import { getConnectionManager, Repository } from 'typeorm';
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions'; import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
import { UserGroupNotFoundError, UserIdsNotMatchingError, UserNotFoundError } from '../errors/UserErrors'; import { UserIdsNotMatchingError, UserNotFoundError } from '../errors/UserErrors';
import { UserGroupNotFoundError } from '../errors/UserGroupErrors';
import { CreateUser } from '../models/actions/CreateUser'; import { CreateUser } from '../models/actions/CreateUser';
import { User } from '../models/entities/User'; import { User } from '../models/entities/User';

View File

@ -1,6 +1,9 @@
import { IsString } from 'class-validator'; import { IsString } from 'class-validator';
import { NotAcceptableError, NotFoundError } from 'routing-controllers'; import { NotAcceptableError, NotFoundError } from 'routing-controllers';
/**
* Error to throw, when to provided address doesn't belong to the accepted types.
*/
export class AddressWrongTypeError extends NotAcceptableError { export class AddressWrongTypeError extends NotAcceptableError {
@IsString() @IsString()
name = "AddressWrongTypeError" name = "AddressWrongTypeError"
@ -9,6 +12,9 @@ export class AddressWrongTypeError extends NotAcceptableError {
message = "The address must be an existing adress's id. \n You provided a object of another type." message = "The address must be an existing adress's id. \n You provided a object of another type."
} }
/**
* Error to throw, when a non-existant address get's loaded.
*/
export class AddressNotFoundError extends NotFoundError { export class AddressNotFoundError extends NotFoundError {
@IsString() @IsString()
name = "AddressNotFoundError" name = "AddressNotFoundError"

View File

@ -2,7 +2,7 @@ import { IsString } from 'class-validator';
import { ForbiddenError, NotAcceptableError, NotFoundError, UnauthorizedError } from 'routing-controllers'; import { ForbiddenError, NotAcceptableError, NotFoundError, UnauthorizedError } from 'routing-controllers';
/** /**
* Error to throw when a jwt is expired * Error to throw when a jwt is expired.
*/ */
export class ExpiredJWTError extends UnauthorizedError { export class ExpiredJWTError extends UnauthorizedError {
@IsString() @IsString()
@ -13,7 +13,7 @@ export class ExpiredJWTError extends UnauthorizedError {
} }
/** /**
* Error to throw when a jwt could not be parsed * Error to throw when a jwt could not be parsed.
*/ */
export class IllegalJWTError extends UnauthorizedError { export class IllegalJWTError extends UnauthorizedError {
@IsString() @IsString()
@ -24,7 +24,7 @@ export class IllegalJWTError extends UnauthorizedError {
} }
/** /**
* Error to throw when user is nonexistant or refreshtoken is invalid * Error to throw when user is nonexistant or refreshtoken is invalid.
*/ */
export class UserNonexistantOrRefreshtokenInvalidError extends UnauthorizedError { export class UserNonexistantOrRefreshtokenInvalidError extends UnauthorizedError {
@IsString() @IsString()
@ -35,7 +35,7 @@ export class UserNonexistantOrRefreshtokenInvalidError extends UnauthorizedError
} }
/** /**
* Error to throw when provided credentials are invalid * Error to throw when provided credentials are invalid.
*/ */
export class InvalidCredentialsError extends UnauthorizedError { export class InvalidCredentialsError extends UnauthorizedError {
@IsString() @IsString()
@ -46,7 +46,7 @@ export class InvalidCredentialsError extends UnauthorizedError {
} }
/** /**
* Error to throw when a jwt does not have permission for this route/ action * Error to throw when a jwt does not have permission for this route/action.
*/ */
export class NoPermissionError extends ForbiddenError { export class NoPermissionError extends ForbiddenError {
@IsString() @IsString()
@ -57,7 +57,7 @@ export class NoPermissionError extends ForbiddenError {
} }
/** /**
* Error to thow when no username and no email is set * Error to throw when no username and no email is set.
*/ */
export class UsernameOrEmailNeededError extends NotAcceptableError { export class UsernameOrEmailNeededError extends NotAcceptableError {
@IsString() @IsString()
@ -68,7 +68,7 @@ export class UsernameOrEmailNeededError extends NotAcceptableError {
} }
/** /**
* Error to thow when no password is provided * Error to throw when no password is provided.
*/ */
export class PasswordNeededError extends NotAcceptableError { export class PasswordNeededError extends NotAcceptableError {
@IsString() @IsString()
@ -79,7 +79,7 @@ export class PasswordNeededError extends NotAcceptableError {
} }
/** /**
* Error to thow when no user could be found for provided credential * Error to throw when no user could be found mating the provided credential.
*/ */
export class UserNotFoundError extends NotFoundError { export class UserNotFoundError extends NotFoundError {
@IsString() @IsString()
@ -90,7 +90,7 @@ export class UserNotFoundError extends NotFoundError {
} }
/** /**
* Error to thow when no jwt token was provided * Error to throw when no jwt token was provided (but one had to be).
*/ */
export class JwtNotProvidedError extends NotAcceptableError { export class JwtNotProvidedError extends NotAcceptableError {
@IsString() @IsString()
@ -101,7 +101,7 @@ export class JwtNotProvidedError extends NotAcceptableError {
} }
/** /**
* Error to thow when user was not found or refresh token count was invalid * Error to throw when user was not found or refresh token count was invalid.
*/ */
export class UserNotFoundOrRefreshTokenCountInvalidError extends NotAcceptableError { export class UserNotFoundOrRefreshTokenCountInvalidError extends NotAcceptableError {
@IsString() @IsString()

View File

@ -1,6 +1,9 @@
import { IsString } from 'class-validator'; import { IsString } from 'class-validator';
import { NotAcceptableError, NotFoundError } from 'routing-controllers'; import { NotAcceptableError, NotFoundError } from 'routing-controllers';
/**
* Error to throw, when a provided groupContact doesn't belong to the accepted types.
*/
export class GroupContactWrongTypeError extends NotAcceptableError { export class GroupContactWrongTypeError extends NotAcceptableError {
@IsString() @IsString()
name = "GroupContactWrongTypeError" name = "GroupContactWrongTypeError"
@ -9,6 +12,9 @@ export class GroupContactWrongTypeError extends NotAcceptableError {
message = "The groupContact must be an existing groupContact's id. \n You provided a object of another type." message = "The groupContact must be an existing groupContact's id. \n You provided a object of another type."
} }
/**
* Error to throw, when a non-existant groupContact get's loaded.
*/
export class GroupContactNotFoundError extends NotFoundError { export class GroupContactNotFoundError extends NotFoundError {
@IsString() @IsString()
name = "GroupContactNotFoundError" name = "GroupContactNotFoundError"

View File

@ -26,14 +26,9 @@ export class RunnerIdsNotMatchingError extends NotAcceptableError {
message = "The id's don't match!! \n And if you wanted to change a runner's id: This isn't allowed" message = "The id's don't match!! \n And if you wanted to change a runner's id: This isn't allowed"
} }
export class RunnerOnlyOneGroupAllowedError extends NotAcceptableError { /**
@IsString() * Error to throw when a runner is missing his group association.
name = "RunnerOnlyOneGroupAllowedError" */
@IsString()
message = "Runner's can only be part of one group (team or organisiation)! \n You provided an id for both."
}
export class RunnerGroupNeededError extends NotAcceptableError { export class RunnerGroupNeededError extends NotAcceptableError {
@IsString() @IsString()
name = "RunnerGroupNeededError" name = "RunnerGroupNeededError"
@ -41,12 +36,3 @@ export class RunnerGroupNeededError extends NotAcceptableError {
@IsString() @IsString()
message = "Runner's need to be part of one group (team or organisiation)! \n You provided neither." message = "Runner's need to be part of one group (team or organisiation)! \n You provided neither."
} }
export class RunnerGroupNotFoundError extends NotFoundError {
@IsString()
name = "RunnerGroupNotFoundError"
@IsString()
message = "The group you provided couldn't be located in the system. \n Please check your request."
}

View File

@ -0,0 +1,14 @@
import { IsString } from 'class-validator';
import { NotFoundError } from 'routing-controllers';
/**
* Error to throw when a runner group couldn't be found.
* Implemented this ways to work with the json-schema conversion for openapi.
*/
export class RunnerGroupNotFoundError extends NotFoundError {
@IsString()
name = "RunnerGroupNotFoundError"
@IsString()
message = "RunnerGroup not found!"
}

View File

@ -50,6 +50,9 @@ export class RunnerOrganisationHasTeamsError extends NotAcceptableError {
message = "This organisation still has teams associated with it. \n If you want to delete this organisation with all it's runners and teams ass `?force` to your query." message = "This organisation still has teams associated with it. \n If you want to delete this organisation with all it's runners and teams ass `?force` to your query."
} }
/**
* Error to throw, when a provided runnerOrganisation doesn't belong to the accepted types.
*/
export class RunnerOrganisationWrongTypeError extends NotAcceptableError { export class RunnerOrganisationWrongTypeError extends NotAcceptableError {
@IsString() @IsString()
name = "RunnerOrganisationWrongTypeError" name = "RunnerOrganisationWrongTypeError"

View File

@ -1,16 +1,6 @@
import { IsString } from 'class-validator'; import { IsString } from 'class-validator';
import { NotAcceptableError, NotFoundError } from 'routing-controllers'; import { NotAcceptableError, NotFoundError } from 'routing-controllers';
/**
* Error to throw when a usergroup couldn't be found.
*/
export class UserGroupNotFoundError extends NotFoundError {
@IsString()
name = "UserGroupNotFoundError"
@IsString()
message = "User Group not found!"
}
/** /**
* Error to throw when no username or email is set * Error to throw when no username or email is set

View File

@ -1,6 +1,6 @@
import { IsInt } from 'class-validator'; import { IsInt } from 'class-validator';
import { getConnectionManager } from 'typeorm'; import { getConnectionManager } from 'typeorm';
import { RunnerGroupNotFoundError } from '../../errors/RunnerErrors'; import { RunnerGroupNotFoundError } from '../../errors/RunnerGroupErrors';
import { RunnerOrganisationWrongTypeError } from '../../errors/RunnerOrganisationErrors'; import { RunnerOrganisationWrongTypeError } from '../../errors/RunnerOrganisationErrors';
import { RunnerTeamNeedsParentError } from '../../errors/RunnerTeamErrors'; import { RunnerTeamNeedsParentError } from '../../errors/RunnerTeamErrors';
import { Runner } from '../entities/Runner'; import { Runner } from '../entities/Runner';

View File

@ -2,7 +2,8 @@ import * as argon2 from "argon2";
import { IsEmail, IsOptional, IsPhoneNumber, IsString } from 'class-validator'; import { IsEmail, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
import { getConnectionManager } from 'typeorm'; import { getConnectionManager } from 'typeorm';
import * as uuid from 'uuid'; import * as uuid from 'uuid';
import { UserGroupNotFoundError, UsernameOrEmailNeededError } from '../../errors/UserErrors'; import { UsernameOrEmailNeededError } from '../../errors/UserErrors';
import { UserGroupNotFoundError } from '../../errors/UserGroupErrors';
import { User } from '../entities/User'; import { User } from '../entities/User';
import { UserGroup } from '../entities/UserGroup'; import { UserGroup } from '../entities/UserGroup';