-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #669 from hivemq/fix/http-errors
Align error handling
- Loading branch information
Showing
62 changed files
with
2,435 additions
and
1,294 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
35 changes: 35 additions & 0 deletions
35
hivemq-edge/src/main/java/com/hivemq/api/errors/AlreadyExistsError.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,35 @@ | ||
/* | ||
* Copyright 2019-present HiveMQ GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hivemq.api.errors; | ||
|
||
import com.hivemq.http.HttpStatus; | ||
import com.hivemq.http.error.Error; | ||
import com.hivemq.http.error.ProblemDetails; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class AlreadyExistsError extends ProblemDetails { | ||
public AlreadyExistsError( | ||
final @Nullable String error) { | ||
super( | ||
"ResourceAlreadyExists", | ||
"The resource already exists", | ||
"Requested to create a resource which already exists", | ||
HttpStatus.CONFLICT_409, | ||
List.of(new Error(error == null ? "An unexpected error occurred, check the logs" : error))); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
hivemq-edge/src/main/java/com/hivemq/api/errors/BadRequestError.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,35 @@ | ||
/* | ||
* Copyright 2019-present HiveMQ GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hivemq.api.errors; | ||
|
||
import com.hivemq.http.HttpStatus; | ||
import com.hivemq.http.error.Error; | ||
import com.hivemq.http.error.ProblemDetails; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class BadRequestError extends ProblemDetails { | ||
public BadRequestError( | ||
final @Nullable String error) { | ||
super( | ||
"BadRequestError", | ||
"Request could not be processed", | ||
"Request could not be processed", | ||
HttpStatus.BAD_REQUEST_400, | ||
List.of(new Error(error))); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
hivemq-edge/src/main/java/com/hivemq/api/errors/BodyParameterMissingError.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 @@ | ||
/* | ||
* Copyright 2019-present HiveMQ GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hivemq.api.errors; | ||
|
||
import com.hivemq.http.HttpStatus; | ||
import com.hivemq.http.error.Error; | ||
import com.hivemq.http.error.ProblemDetails; | ||
|
||
import java.util.List; | ||
|
||
public class BodyParameterMissingError extends ProblemDetails { | ||
public BodyParameterMissingError(String parameterName) { | ||
super( | ||
"BodyParameterMissing", | ||
"Required request body parameter missing", | ||
"Required request body parameter missing", | ||
HttpStatus.BAD_REQUEST_400, | ||
List.of(new Error("Request body parameter missing: " + parameterName, parameterName))); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
hivemq-edge/src/main/java/com/hivemq/api/errors/InsufficientStorageError.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,35 @@ | ||
/* | ||
* Copyright 2019-present HiveMQ GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hivemq.api.errors; | ||
|
||
import com.hivemq.http.HttpStatus; | ||
import com.hivemq.http.error.Error; | ||
import com.hivemq.http.error.ProblemDetails; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
public class InsufficientStorageError extends ProblemDetails { | ||
public InsufficientStorageError( | ||
final @NotNull String cause) { | ||
super( | ||
"InsufficientStorage", | ||
"Insufficient Storage", | ||
"Insufficient Storage", | ||
HttpStatus.INSUFFICIENT_STORAGE_507, | ||
List.of(new Error(cause))); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
hivemq-edge/src/main/java/com/hivemq/api/errors/InternalServerError.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,35 @@ | ||
/* | ||
* Copyright 2019-present HiveMQ GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hivemq.api.errors; | ||
|
||
import com.hivemq.http.HttpStatus; | ||
import com.hivemq.http.error.Error; | ||
import com.hivemq.http.error.ProblemDetails; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class InternalServerError extends ProblemDetails { | ||
public InternalServerError( | ||
final @Nullable String error) { | ||
super( | ||
"InternalServerError", | ||
"InternalError", | ||
"Internal error", | ||
HttpStatus.INTERNAL_SERVER_ERROR_500, | ||
List.of(new Error(error == null ? "An unexpected error occurred, check the logs" : error))); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
hivemq-edge/src/main/java/com/hivemq/api/errors/InvalidInputError.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,35 @@ | ||
/* | ||
* Copyright 2019-present HiveMQ GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hivemq.api.errors; | ||
|
||
import com.hivemq.http.HttpStatus; | ||
import com.hivemq.http.error.Error; | ||
import com.hivemq.http.error.ProblemDetails; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class InvalidInputError extends ProblemDetails { | ||
public InvalidInputError( | ||
final @Nullable String error) { | ||
super( | ||
"InvalidInputError", | ||
"Invalid input", | ||
"JSON failed validation.", | ||
HttpStatus.BAD_REQUEST_400, | ||
List.of(new Error("Unparseable JSON: " + error, null))); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
hivemq-edge/src/main/java/com/hivemq/api/errors/InvalidQueryParameterError.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 @@ | ||
/* | ||
* Copyright 2019-present HiveMQ GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hivemq.api.errors; | ||
|
||
import com.hivemq.http.HttpStatus; | ||
import com.hivemq.http.error.Error; | ||
import com.hivemq.http.error.ProblemDetails; | ||
|
||
import java.util.List; | ||
|
||
public class InvalidQueryParameterError extends ProblemDetails { | ||
public InvalidQueryParameterError(String parameterName, String reason) { | ||
super( | ||
"InvalidQueryParameter", | ||
"Query parameter is invalid", | ||
"Query parameter is invalid", | ||
HttpStatus.BAD_REQUEST_400, | ||
List.of(new Error(String.format("Query parameter %s is invalid: %s", parameterName, reason), parameterName))); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
hivemq-edge/src/main/java/com/hivemq/api/errors/InvalidQueryParameterErrors.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 @@ | ||
/* | ||
* Copyright 2019-present HiveMQ GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hivemq.api.errors; | ||
|
||
import com.hivemq.http.HttpStatus; | ||
import com.hivemq.http.error.Error; | ||
import com.hivemq.http.error.ProblemDetails; | ||
|
||
import java.util.List; | ||
|
||
public class InvalidQueryParameterErrors extends ProblemDetails { | ||
public InvalidQueryParameterErrors(List<Error> errors) { | ||
super( | ||
"InvalidQueryParameter", | ||
"Query parameter is invalid", | ||
"Query parameter is invalid", | ||
HttpStatus.BAD_REQUEST_400, | ||
errors); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
hivemq-edge/src/main/java/com/hivemq/api/errors/MethodNotAllowedError.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,32 @@ | ||
/* | ||
* Copyright 2019-present HiveMQ GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hivemq.api.errors; | ||
|
||
import com.hivemq.http.HttpStatus; | ||
import com.hivemq.http.error.ProblemDetails; | ||
|
||
import java.util.List; | ||
|
||
public class MethodNotAllowedError extends ProblemDetails { | ||
public MethodNotAllowedError() { | ||
super( | ||
"MethodNotAllowedError", | ||
"Method not allowed", | ||
"Method not allowed", | ||
HttpStatus.METHOD_NOT_ALLOWED_405, | ||
List.of()); | ||
} | ||
} |
Oops, something went wrong.