Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping(value = "/v1")
Expand Down Expand Up @@ -61,7 +62,24 @@ public Barcode getScannerData(@Parameter(description = "Scanner to Call") @PathV
log.successAPI("API Request Completed Successfully", 1, url, data == null ? null : data.toString(), 200);
return data;
} catch (ScannerException scannerException) {
log.failureAPI("API Request Failed with ScannerException", 13, url, scannerException.getDeviceError() == null ? null : scannerException.getDeviceError().toString(), scannerException.getDeviceError() == null ? 0 : scannerException.getDeviceError().getStatusCode().value(), scannerException);
// If getCode() is DISABLED or DEVICE_BUSY, it means the scan request was cancelled either by the client or due to another scan request, so we log it as a less severe failure than other exceptions
DeviceError error = scannerException.getDeviceError();
String code = error != null ? error.getCode() : null;
int status = (error != null && error.getStatusCode() != null)
? error.getStatusCode().value()
: 0;

int severity = (!Objects.equals(code, "DISABLED") &&
!Objects.equals(code, "DEVICE_BUSY")) ? 13 : 1;

log.failureAPI(
"API Request Failed with ScannerException",
severity,
url,
error != null ? error.toString() : null,
status,
scannerException
);
throw scannerException;
}
} else {
Expand Down Expand Up @@ -92,7 +110,23 @@ public void cancelScanRequest() throws ScannerException {
scannerManager.cancelScanRequest();
log.successAPI("API Request Completed Successfully", 1, url, "OK", 200);
} catch (ScannerException scannerException) {
log.failureAPI("API Request Failed with ScannerException", 13, url, scannerException.getDeviceError() == null ? null : scannerException.getDeviceError().toString(), scannerException.getDeviceError() == null ? 0 : scannerException.getDeviceError().getStatusCode().value(), scannerException);
// If getCode() is ALREADY_DISABLED, it means the scan request was already cancelled before this call, so we log it as a less severe failure than other exceptions
DeviceError error = scannerException.getDeviceError();
String code = error != null ? error.getCode() : null;
int status = (error != null && error.getStatusCode() != null)
? error.getStatusCode().value()
: 0;

int severity = !Objects.equals(code, "ALREADY_DISABLED") ? 13 : 1;

log.failureAPI(
"API Request Failed with ScannerException",
severity,
url,
error != null ? error.toString() : null,
status,
scannerException
);
throw scannerException;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public Void cancelScannerData() {
try{
disable();
} catch(JposException jposException){
log.failure("Received exception in cancelScannerData", 17, jposException);
log.failure("Received exception in cancelScannerData", 1, jposException);
} finally {
deviceListener.stopWaitingForData();
}
Expand Down Expand Up @@ -248,7 +248,7 @@ protected void enable() throws JposException {
throw jposException;
}
}
log.success(getScannerType() + " scanner enabled", 9);
log.success(getScannerType() + " scanner enabled", 1);
log.success(getScannerType() + " enable(out)", 1);
}

Expand Down Expand Up @@ -276,7 +276,7 @@ private void disable() throws JposException {
throw jposException;
}
}
log.success(getScannerType() + " scanner disabled", 9);
log.success(getScannerType() + " scanner disabled", 1);
log.success(getScannerType() + " disable(out)", 1);
}

Expand Down