Skip to content

Commit

Permalink
Merge pull request fmeringdal#19 from VerHext/main
Browse files Browse the repository at this point in the history
fix: application crash by wrong / missing secret key & extends error handling for resources
  • Loading branch information
fmeringdal authored Jun 21, 2021
2 parents 12705fd + 404d0d7 commit a90299e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion frontend/src/shared/components/FileUploadModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export const FileUploadModal = (props: Props) => {
);
const resource = res.getValue().resource;
resources.push(resource);
} catch (error) {}
} catch (error) {
alert(error?.response?.data?.message);
}
}
props.onDone({
uploadedResources: resources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export class CreateResourceController extends BaseController<BodySchema, PathPar
return res.forbidden(e.message);
case CreateResourceUseCaseErrors.MeetingNotFoundError:
return res.notFound(e.message);
case CreateResourceUseCaseErrors.ResourceUploadNotSupportedError:
return res.forbidden(e.message);
case CreateResourceUseCaseErrors.CanvasNotFoundError:
return res.notFound(e.message);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ export namespace CreateResourceUseCaseErrors {
} as UseCaseError);
}
}

export class ResourceUploadNotSupportedError extends Result<UseCaseError> {
constructor() {
super(false, {
message: `Resource upload is not supported on this server.`,
} as UseCaseError);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { awsConfig } from '../../../../config';
import { AppError } from '../../../../shared/core/AppError';
import { Either, left, right } from '../../../../shared/core/Result';
import { UseCase } from '../../../../shared/core/UseCase';
Expand Down Expand Up @@ -40,6 +41,10 @@ export class CreateResourceUseCase implements UseCase<CreateResourceDTO, Promise
return left(new CreateResourceUseCaseErrors.CanvasNotFoundError(request.meetingId, request.canvasId));
}

if (!awsConfig.mediaBucket) {
return left(new CreateResourceUseCaseErrors.ResourceUploadNotSupportedError());
}

const resourceId = new UniqueEntityID();

const key = `meetings/${meeting.meetingId.toString()}/resources/${resourceId.toString()}`;
Expand Down
4 changes: 2 additions & 2 deletions server/src/shared/infra/http/utils/Middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export class Middleware {
: '';

if (!apiKey) {
this.endRequest(403, 'Invalid secret api key provided', res);
return this.endRequest(403, 'Invalid secret api key provided', res);
}

const account = await this.accountRepo.getAccountBySecretKey(apiKey);
if (!account) {
this.endRequest(403, 'Invalid secret api key provided', res);
return this.endRequest(403, 'Invalid secret api key provided', res);
}

(req as DecodedExpressRequest).decoded = {
Expand Down

0 comments on commit a90299e

Please sign in to comment.