Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADH-4795] Introduce API error codes #80

Merged
merged 4 commits into from
Aug 22, 2024
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
1 change: 1 addition & 0 deletions BUILDING.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Maven build goals:
Build options:

* Use -Pnative to compile/bundle native code
* Use -Pweb-ui to compile/bundle frontend app
* Use -Psrc to create a project source TAR.GZ
* Use -Dtar to create a TAR with the distribution (using -Pdist)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Currently SSM supports ADH 3.2.4_arenadata2 (which is based on hadoop-3.2.4).
So you can build SSM with the following commands accordingly.

```
mvn package -D skipTests -P dist,web,hadoop-3.2
mvn package -DskipTests -Pdist,web-ui,hadoop-3.2
```

Then a package named as `smart-data-${version}.tar.gz` will be generated under `smart-dist/target`.
Expand Down
4 changes: 2 additions & 2 deletions docs/ssm-deployment-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ Download SSM branch from Github https://github.com/arenadata/SSM/

### For Hadoop 3.2.*

mvn clean package -Pdist,web,hadoop-3.2 -DskipTests
mvn clean package -Pdist,web-ui,hadoop-3.2 -DskipTests


### For Hadoop 3.3.*

mvn clean package -Pdist,web,hadoop-3.3 -DskipTests
mvn clean package -Pdist,web-ui,hadoop-3.3 -DskipTests

A tar distribution package will be generated under 'smart-dist/target'. Unzip the tar distribution package to ${SMART_HOME} directory, and SSM configuration files are under '${SMART_HOME}/conf'.
For more detailed information, please refer to BUILDING.txt file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
import java.io.IOException;

public class SsmParseException extends IOException {
public SsmParseException() {
super();
}

public SsmParseException(String message) {
super(message);
Expand All @@ -31,8 +28,4 @@ public SsmParseException(String message) {
public SsmParseException(String message, Throwable cause) {
super(message, cause);
}

public SsmParseException(Exception cause) {
super(cause);
}
}
61 changes: 0 additions & 61 deletions smart-web-server/.openapi-generator/FILES

This file was deleted.

1 change: 0 additions & 1 deletion smart-web-server/.openapi-generator/VERSION

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions smart-web-server/license-header.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import org.smartdata.metastore.MetaStoreException;
import org.springframework.beans.TypeMismatchException;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.dao.DataAccessException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.support.MetaDataAccessException;
import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
Expand All @@ -44,8 +46,21 @@
public class SmartExceptionHandler extends ResponseEntityExceptionHandler {
private static final Logger LOG = LoggerFactory.getLogger(SmartExceptionHandler.class);

// TODO refactor error handling and status codes after api refactoring
@ExceptionHandler(value = {IOException.class, MetaStoreException.class})
@ExceptionHandler(value = {
MetaStoreException.class,
MetaDataAccessException.class,
DataAccessException.class
})
protected ResponseEntity<Object> handleDbExceptions(
RuntimeException exception, WebRequest request) {
return handleExceptionInternal(
exception,
request,
SsmErrorCode.DB_ERROR,
HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(value = IOException.class)
protected ResponseEntity<Object> handleSsmExceptions(
RuntimeException exception, WebRequest request) {
return handleExceptionInternal(
Expand All @@ -55,8 +70,17 @@ protected ResponseEntity<Object> handleSsmExceptions(
HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(value = {
ConstraintViolationException.class, SsmParseException.class})
@ExceptionHandler(value = SsmParseException.class)
protected ResponseEntity<Object> handleParseExceptions(
SsmParseException exception, WebRequest request) {
return handleExceptionInternal(
exception,
request,
SsmErrorCode.PARSE_ERROR,
HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(value = ConstraintViolationException.class)
protected ResponseEntity<Object> handleValidationExceptions(
Exception exception, WebRequest request) {
return handleExceptionInternal(
Expand Down Expand Up @@ -109,7 +133,7 @@ protected ResponseEntity<Object> handleBindException(
request,
HttpStatus.BAD_REQUEST,
new ErrorDto<>(
SsmErrorCode.VALIDATION_ERROR.toString(),
SsmErrorCode.VALIDATION_ERROR.getCode(),
errorMessage,
ExceptionUtils.getStackTrace(exception))
);
Expand All @@ -118,7 +142,7 @@ protected ResponseEntity<Object> handleBindException(
private ResponseEntity<Object> handleExceptionInternal(
Exception exception, WebRequest request, SsmErrorCode errorCode, HttpStatus status) {
ErrorDto<String> errorBody = new ErrorDto<>(
errorCode.toString(),
errorCode.getCode(),
exception.getMessage(),
ExceptionUtils.getStackTrace(exception));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@
*/
package org.smartdata.server.error;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Getter
public enum SsmErrorCode {
VALIDATION_ERROR,
SSM_INTERNAL_ERROR
SSM_INTERNAL_ERROR("ssm_00"),
VALIDATION_ERROR("ssm_01"),
PARSE_ERROR("ssm_02"),
DB_ERROR("db_01");

private final String code;
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public ErrorResponseDto code(String code) {
}

/**
* Error code
* Error code. Can be in the form of `ssm_XX` or `db_XX`
* @return code
*/
@NotNull
@Schema(name = "code", description = "Error code", requiredMode = Schema.RequiredMode.REQUIRED)
@Schema(name = "code", description = "Error code. Can be in the form of `ssm_XX` or `db_XX`", requiredMode = Schema.RequiredMode.REQUIRED)
@JsonProperty("code")
public String getCode() {
return code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ type: object
properties:
code:
type: string
description: Error code
description: Error code. Can be in the form of `ssm_XX` or `db_XX`
message:
type: string
description: Detailed error message
Expand Down
2 changes: 1 addition & 1 deletion smart-web-server/src/main/resources/static/ssm-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ components:
body: "{}"
properties:
code:
description: Error code
description: Error code. Can be in the form of `ssm_XX` or `db_XX`
type: string
message:
description: Detailed error message
Expand Down
Loading