-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
104 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
griffin-metric/src/main/java/org/apache/griffin/metric/exception/GriffinErr.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.apache.griffin.metric.exception; | ||
|
||
import lombok.Getter; | ||
|
||
public enum GriffinErr { | ||
commonError(101, "Hit an error without details."), | ||
validationError(102, "Data validation fails due to [%s]"), | ||
// db operation errors | ||
dbInsertionError(301, "Fail to insert a record."), | ||
dbUpdateError(302, "Fail to update a record."), | ||
dbDeletionError(303, "Fail to delete a record."), | ||
; | ||
|
||
@Getter | ||
private int code; | ||
|
||
@Getter | ||
private String message; | ||
|
||
GriffinErr(int code, String message) { | ||
this.code = code; | ||
this.message = message; | ||
} | ||
|
||
public GriffinErrorEntity buildErrorEntity() { | ||
return new GriffinErrorEntity(this); | ||
} | ||
|
||
public GriffinErrorEntity buildErrorEntity(String message) { | ||
return new GriffinErrorEntity(this, message); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
griffin-metric/src/main/java/org/apache/griffin/metric/exception/GriffinErrorEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.apache.griffin.metric.exception; | ||
|
||
import lombok.Data; | ||
import org.apache.griffin.metric.entity.BaseEntity; | ||
|
||
@Data | ||
public class GriffinErrorEntity extends BaseEntity { | ||
|
||
private Integer code; | ||
|
||
private String message; | ||
|
||
public GriffinErrorEntity(GriffinErr err) { | ||
this.code = err.getCode(); | ||
this.message = err.getMessage(); | ||
} | ||
|
||
public GriffinErrorEntity(GriffinErr err, String details) { | ||
this.code = err.getCode(); | ||
this.message = String.format(err.getMessage(), details); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
griffin-metric/src/main/java/org/apache/griffin/metric/exception/GriffinException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
package org.apache.griffin.metric.exception; | ||
|
||
import lombok.Getter; | ||
|
||
public class GriffinException extends RuntimeException { | ||
@Getter | ||
private final GriffinErr error; | ||
|
||
public GriffinException(String message) { | ||
super(message); | ||
this.error = GriffinErr.commonError; | ||
} | ||
|
||
public GriffinException(Throwable cause) { | ||
super(cause); | ||
this.error = GriffinErr.commonError; | ||
} | ||
|
||
public GriffinException(String message, Throwable cause) { | ||
super(message, cause); | ||
this.error = GriffinErr.commonError; | ||
} | ||
|
||
public GriffinException(String message, GriffinErr error) { | ||
super(message); | ||
this.error = error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters