Skip to content

Commit 7dd98d5

Browse files
added some generic messages for the unsuccessful CommandResults
1 parent c8ca491 commit 7dd98d5

2 files changed

Lines changed: 34 additions & 9 deletions

File tree

commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandErrorCodes.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,24 @@ private CommandErrorCodes() {
88
}
99

1010
public static final @NotNull String FORBIDDEN_NO_PERMISSION = "WLib:Forbidden/NoPermission";
11+
public static final @NotNull String FORBIDDEN_GENERIC = "WLib:Forbidden/Generic";
12+
1113
public static final @NotNull String NOT_FOUND_NODE_NOT_FOUND = "WLib:NotFound/NodeNotFound";
14+
public static final @NotNull String NOT_FOUND_GENERIC = "WLib:NotFound/Generic";
15+
1216
public static final @NotNull String NOT_IMPLEMENTED_NO_COMMAND_EXECUTOR = "WLib:NotImplemented/NoCommandExecutor";
17+
18+
public static final @NotNull String BAD_REQUEST_GENERIC = "WLib:BadRequest/Generic";
1319
public static final @NotNull String BAD_REQUEST_PARSE_ERROR = "WLib:BadRequest/ParseError";
1420
public static final @NotNull String BAD_REQUEST_EMPTY_INPUT = "WLib:BadRequest/EmptyInput";
21+
1522
public static final @NotNull String UNPROCESSABLE_CONTENT_INVALID_INPUT = "WLib:UnprocessableContent/InvalidInput";
23+
24+
public static final @NotNull String CONFLICT_GENERIC = "WLib:Conflict/Generic";
25+
26+
public static final @NotNull String GENERIC_ERROR_GENERIC = "WLib:GenericError/Generic";
27+
28+
public static final @NotNull String INVALID_SENDER_GENERIC = "WLib:InvalidSender/Generic";
29+
30+
public static final @NotNull String UNAUTHORIZED_GENERIC = "WLib:Unauthorized/Generic";
1631
}

commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,71 +78,71 @@ public String toString() {
7878
//ERROR
7979

8080
public static <T> @NotNull CommandResult<T> badRequest() {
81-
return new CommandResult<>(null, Type.BAD_REQUEST, null);
81+
return new CommandResult<>(null, Type.BAD_REQUEST, ErrorDetails.BAD_REQUEST);
8282
}
8383

8484
public static <T> @NotNull CommandResult<T> badRequest(@NotNull ErrorDetails errorDetails) {
8585
return new CommandResult<>(null, Type.BAD_REQUEST, errorDetails);
8686
}
8787

8888
public static <T> @NotNull CommandResult<T> conflict() {
89-
return new CommandResult<>(null, Type.CONFLICT, null);
89+
return new CommandResult<>(null, Type.CONFLICT, ErrorDetails.CONFLICT);
9090
}
9191

9292
public static <T> @NotNull CommandResult<T> conflict(@NotNull ErrorDetails errorDetails) {
9393
return new CommandResult<>(null, Type.CONFLICT, errorDetails);
9494
}
9595

9696
public static <T> @NotNull CommandResult<T> forbidden() {
97-
return new CommandResult<>(null, Type.FORBIDDEN, null);
97+
return new CommandResult<>(null, Type.FORBIDDEN, ErrorDetails.FORBIDDEN);
9898
}
9999

100100
public static <T> @NotNull CommandResult<T> forbidden(@NotNull ErrorDetails errorDetails) {
101101
return new CommandResult<>(null, Type.FORBIDDEN, errorDetails);
102102
}
103103

104104
public static <T> @NotNull CommandResult<T> genericError() {
105-
return new CommandResult<>(null, Type.GENERIC_ERROR, null);
105+
return new CommandResult<>(null, Type.GENERIC_ERROR, ErrorDetails.GENERIC_ERROR);
106106
}
107107

108108
public static <T> @NotNull CommandResult<T> genericError(@NotNull ErrorDetails errorDetails) {
109109
return new CommandResult<>(null, Type.GENERIC_ERROR, errorDetails);
110110
}
111111

112112
public static <T> @NotNull CommandResult<T> invalidSender() {
113-
return new CommandResult<>(null, Type.INVALID_SENDER, null);
113+
return new CommandResult<>(null, Type.INVALID_SENDER, ErrorDetails.INVALID_SENDER);
114114
}
115115

116116
public static <T> @NotNull CommandResult<T> invalidSender(@NotNull ErrorDetails errorDetails) {
117117
return new CommandResult<>(null, Type.INVALID_SENDER, errorDetails);
118118
}
119119

120120
public static <T> @NotNull CommandResult<T> notFound() {
121-
return new CommandResult<>(null, Type.NOT_FOUND, null);
121+
return new CommandResult<>(null, Type.NOT_FOUND, ErrorDetails.NOT_FOUND);
122122
}
123123

124124
public static <T> @NotNull CommandResult<T> notFound(@NotNull ErrorDetails errorDetails) {
125125
return new CommandResult<>(null, Type.NOT_FOUND, errorDetails);
126126
}
127127

128128
public static <T> @NotNull CommandResult<T> unauthorized() {
129-
return new CommandResult<>(null, Type.UNAUTHORIZED, null);
129+
return new CommandResult<>(null, Type.UNAUTHORIZED, ErrorDetails.UNAUTHORIZED);
130130
}
131131

132132
public static <T> @NotNull CommandResult<T> unauthorized(@NotNull ErrorDetails errorDetails) {
133133
return new CommandResult<>(null, Type.UNAUTHORIZED, errorDetails);
134134
}
135135

136136
public static <T> @NotNull CommandResult<T> unprocessableContent() {
137-
return new CommandResult<>(null, Type.UNPROCESSABLE_CONTENT, null);
137+
return new CommandResult<>(null, Type.UNPROCESSABLE_CONTENT, ErrorDetails.UNPROCESSABLE_CONTENT);
138138
}
139139

140140
public static <T> @NotNull CommandResult<T> unprocessableContent(@NotNull ErrorDetails errorDetails) {
141141
return new CommandResult<>(null, Type.UNPROCESSABLE_CONTENT, errorDetails);
142142
}
143143

144144
public static <T> @NotNull CommandResult<T> notImplemented() {
145-
return new CommandResult<>(null, Type.NOT_IMPLEMENTED, null);
145+
return new CommandResult<>(null, Type.NOT_IMPLEMENTED, ErrorDetails.NOT_IMPLEMENTED);
146146
}
147147

148148
public static <T> @NotNull CommandResult<T> notImplemented(@NotNull ErrorDetails errorDetails) {
@@ -173,6 +173,16 @@ public boolean isSuccess() {
173173

174174
public record ErrorDetails(@NotNull String code, @NotNull String message, @NotNull String detail) {
175175

176+
public static final @NotNull ErrorDetails BAD_REQUEST = new ErrorDetails(CommandErrorCodes.BAD_REQUEST_GENERIC, "Bad request", "Bad request");
177+
public static final @NotNull ErrorDetails CONFLICT = new ErrorDetails(CommandErrorCodes.CONFLICT_GENERIC, "Conflict", "The request could not be completed due to a conflict with the current state of the target resource");
178+
public static final @NotNull ErrorDetails FORBIDDEN = new ErrorDetails(CommandErrorCodes.FORBIDDEN_GENERIC, "Forbidden", "Access to the requested resource is forbidden");
179+
public static final @NotNull ErrorDetails GENERIC_ERROR = new ErrorDetails(CommandErrorCodes.GENERIC_ERROR_GENERIC, "Internal server error", "An unexpected error occurred while processing the request");
180+
public static final @NotNull ErrorDetails INVALID_SENDER = new ErrorDetails(CommandErrorCodes.INVALID_SENDER_GENERIC, "Invalid sender", "The sender of the command is invalid or not permitted");
181+
public static final @NotNull ErrorDetails NOT_FOUND = new ErrorDetails(CommandErrorCodes.NOT_FOUND_GENERIC, "Not found", "The requested resource could not be found");
182+
public static final @NotNull ErrorDetails UNAUTHORIZED = new ErrorDetails(CommandErrorCodes.UNAUTHORIZED_GENERIC, "Unauthorized", "Authentication is required and has failed or has not been provided");
183+
public static final @NotNull ErrorDetails UNPROCESSABLE_CONTENT = new ErrorDetails(CommandErrorCodes.UNPROCESSABLE_CONTENT_INVALID_INPUT, "Unprocessable content", "The request was well-formed but contained semantic errors");
184+
public static final @NotNull ErrorDetails NOT_IMPLEMENTED = new ErrorDetails(CommandErrorCodes.NOT_IMPLEMENTED_NO_COMMAND_EXECUTOR, "Not implemented", "The requested functionality is not implemented");
185+
176186
private static final @NotNull ErrorDetails EMPTY_INPUT = new ErrorDetails(CommandErrorCodes.BAD_REQUEST_EMPTY_INPUT, "The input can not be empty", "The input can not be empty");
177187

178188
public static @NotNull ErrorDetails noCommandExecutor(@NotNull String command, @NotNull String node) {

0 commit comments

Comments
 (0)