Search in sources :

Example 16 with NotFoundException

use of com.formkiq.lambda.apigateway.exception.NotFoundException in project formkiq-core by formkiq.

the class AbstractApiRequestHandler method handleRequest.

@Override
public void handleRequest(final InputStream input, final OutputStream output, final Context context) throws IOException {
    LambdaLogger logger = context.getLogger();
    ApiGatewayRequestEvent event = getApiGatewayEvent(input, logger, getAwsServices());
    ApiAuthorizer authorizer = new ApiAuthorizer(event);
    try {
        ApiRequestHandlerResponse object = processRequest(logger, event, authorizer);
        processResponse(authorizer, event, object);
        buildResponse(logger, output, object.getStatus(), object.getHeaders(), object.getResponse());
    } catch (NotFoundException e) {
        buildResponse(logger, output, SC_NOT_FOUND, Collections.emptyMap(), new ApiResponseError(e.getMessage()));
    } catch (TooManyRequestsException e) {
        buildResponse(logger, output, SC_TOO_MANY_REQUESTS, Collections.emptyMap(), new ApiResponseError(e.getMessage()));
    } catch (BadException | InvalidConditionsException | DateTimeException e) {
        buildResponse(logger, output, SC_BAD_REQUEST, Collections.emptyMap(), new ApiResponseError(e.getMessage()));
    } catch (ForbiddenException e) {
        buildResponse(logger, output, SC_FORBIDDEN, Collections.emptyMap(), new ApiResponseError(e.getMessage()));
    } catch (UnauthorizedException e) {
        buildResponse(logger, output, SC_UNAUTHORIZED, Collections.emptyMap(), new ApiResponseError(e.getMessage()));
    } catch (NotImplementedException e) {
        buildResponse(logger, output, SC_NOT_IMPLEMENTED, Collections.emptyMap(), new ApiResponseError(e.getMessage()));
    } catch (Exception e) {
        logError(logger, e);
        buildResponse(logger, output, SC_ERROR, Collections.emptyMap(), new ApiResponseError("Internal Server Error"));
    }
}
Also used : ForbiddenException(com.formkiq.lambda.apigateway.exception.ForbiddenException) NotImplementedException(com.formkiq.lambda.apigateway.exception.NotImplementedException) NotFoundException(com.formkiq.lambda.apigateway.exception.NotFoundException) BadException(com.formkiq.lambda.apigateway.exception.BadException) ForbiddenException(com.formkiq.lambda.apigateway.exception.ForbiddenException) NotImplementedException(com.formkiq.lambda.apigateway.exception.NotImplementedException) DateTimeException(java.time.DateTimeException) UnauthorizedException(com.formkiq.lambda.apigateway.exception.UnauthorizedException) IOException(java.io.IOException) NotFoundException(com.formkiq.lambda.apigateway.exception.NotFoundException) BadException(com.formkiq.lambda.apigateway.exception.BadException) TooManyRequestsException(com.formkiq.lambda.apigateway.exception.TooManyRequestsException) InvalidConditionsException(com.formkiq.stacks.dynamodb.InvalidConditionsException) TooManyRequestsException(com.formkiq.lambda.apigateway.exception.TooManyRequestsException) InvalidConditionsException(com.formkiq.stacks.dynamodb.InvalidConditionsException) DateTimeException(java.time.DateTimeException) UnauthorizedException(com.formkiq.lambda.apigateway.exception.UnauthorizedException) LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger)

Aggregations

NotFoundException (com.formkiq.lambda.apigateway.exception.NotFoundException)16 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)14 ApiMessageResponse (com.formkiq.lambda.apigateway.ApiMessageResponse)7 ApiResponse (com.formkiq.lambda.apigateway.ApiResponse)6 BadException (com.formkiq.lambda.apigateway.exception.BadException)5 DocumentTag (com.formkiq.stacks.dynamodb.DocumentTag)5 ApiMapResponse (com.formkiq.lambda.apigateway.ApiMapResponse)4 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)4 DocumentItem (com.formkiq.stacks.dynamodb.DocumentItem)4 DocumentService (com.formkiq.stacks.dynamodb.DocumentService)4 Date (java.util.Date)4 ApiUrlResponse (com.formkiq.stacks.api.ApiUrlResponse)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 S3Client (software.amazon.awssdk.services.s3.S3Client)2 LambdaLogger (com.amazonaws.services.lambda.runtime.LambdaLogger)1 S3ObjectMetadata (com.formkiq.aws.s3.S3ObjectMetadata)1 S3Service (com.formkiq.aws.s3.S3Service)1 ApiGatewayRequestHandler (com.formkiq.lambda.apigateway.ApiGatewayRequestHandler)1 ApiPagination (com.formkiq.lambda.apigateway.ApiPagination)1