Skip to content

Commit

Permalink
[ANCHOR-628] Reduce log level client errors in 2.x (#1330)
Browse files Browse the repository at this point in the history
### Description

Some exceptions thrown from the services are translated to HTTP 400s.
They are not errors and should be logged as INFO.

### Context

Improve the logging. 

### Testing

- `./gradlew test`

### Documentation

N/A

### Known limitations

N/A
  • Loading branch information
lijamie98 authored Apr 23, 2024
1 parent aa3b173 commit 2fea38d
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.stellar.anchor.platform.controller;

import static org.stellar.anchor.util.Log.errorEx;
import static org.stellar.anchor.util.Log.infoF;

import javax.transaction.NotSupportedException;
import org.springframework.http.HttpStatus;
Expand All @@ -21,70 +22,71 @@ public abstract class AbstractControllerExceptionHandler {
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler({SepValidationException.class, BadRequestException.class})
public SepExceptionResponse handleBadRequest(AnchorException ex) {
errorEx(ex);
infoF("Bad request: {}", ex.getMessage());
return new SepExceptionResponse(ex.getMessage());
}

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingServletRequestParameterException.class)
public SepExceptionResponse handleMissingParams(MissingServletRequestParameterException ex) {
errorEx(ex);
infoF("Missing server request parameters: {}", ex.getMessage());
String name = ex.getParameterName();
return new SepExceptionResponse(String.format("The \"%s\" parameter is missing.", name));
}

@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public SepExceptionResponse handleRandomException(HttpMessageNotReadableException ex) {
errorEx(ex);
infoF("Spring is unable to read HTTP message: {}", ex.getMessage());
return new SepExceptionResponse("Your request body is wrong in some way.");
}

@ResponseStatus(HttpStatus.FORBIDDEN)
@ExceptionHandler({SepNotAuthorizedException.class})
public SepExceptionResponse handleAuthError(SepException ex) {
errorEx(ex);
infoF("SEP-10 authorization failure: {}", ex.getMessage());
return new SepExceptionResponse(ex.getMessage());
}

@ExceptionHandler(SepCustomerInfoNeededException.class)
@ResponseStatus(value = HttpStatus.FORBIDDEN)
public CustomerInfoNeededResponse handle(SepCustomerInfoNeededException ex) {
infoF("Customer information is needed: {}", ex.getMessage());
return new CustomerInfoNeededResponse(ex.getFields());
}

@ExceptionHandler({SepNotFoundException.class, NotFoundException.class})
@ResponseStatus(value = HttpStatus.NOT_FOUND)
SepExceptionResponse handleNotFound(AnchorException ex) {
errorEx(ex);
infoF("Not found: {}", ex.getMessage());
return new SepExceptionResponse(ex.getMessage());
}

@ResponseStatus(HttpStatus.NOT_IMPLEMENTED)
@ExceptionHandler({NotSupportedException.class})
public SepExceptionResponse handleNotImplementedError(Exception ex) {
errorEx(ex);
infoF("Not implemented: {}", ex.getMessage());
return new SepExceptionResponse(ex.getMessage());
}

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler({CustodyBadRequestException.class})
public CustodyExceptionResponse handleCustodyBadRequest(AnchorException ex) {
errorEx(ex);
infoF("Bad request (custody server): {}", ex.getMessage());
return new CustodyExceptionResponse(ex.getMessage());
}

@ResponseStatus(value = HttpStatus.NOT_FOUND)
@ExceptionHandler({CustodyNotFoundException.class})
public CustodyExceptionResponse handleCustodyNotFound(AnchorException ex) {
errorEx(ex);
infoF("Resource not found (custody server): {}", ex.getMessage());
return new CustodyExceptionResponse(ex.getMessage());
}

@ResponseStatus(HttpStatus.TOO_MANY_REQUESTS)
@ExceptionHandler({CustodyTooManyRequestsException.class})
public CustodyExceptionResponse handleCustodyTooManyRequestsError(AnchorException ex) {
errorEx(ex);
infoF("Too many requests (custody server): {}", ex.getMessage());
return new CustodyExceptionResponse(ex.getMessage());
}

Expand Down

0 comments on commit 2fea38d

Please sign in to comment.