mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-15 05:41:51 +08:00
Moved BadRequestException to API
Changed Bad Request response to JSON: { "status": 400, "error": "message", "target": "/requested/target" }
This commit is contained in:
parent
0a8b0e273c
commit
68be3117b1
@ -14,14 +14,17 @@
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.exceptions.connection;
|
||||
package com.djrapitops.plan.delivery.web.resolver.exception;
|
||||
|
||||
/**
|
||||
* Thrown when connection is returned 401 Bad Request.
|
||||
* Throw this exception when a Resolver gets invalid query for JSON.
|
||||
* <p>
|
||||
* Plan will construct bad request error json automatically.
|
||||
* Note that you might need to handle the error page, which is json: {@code {"status": 400, "error": "message"}}
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class BadRequestException extends WebException {
|
||||
public class BadRequestException extends IllegalArgumentException {
|
||||
|
||||
public BadRequestException(String message) {
|
||||
super(message);
|
@ -33,6 +33,7 @@ import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.Database;
|
||||
import com.djrapitops.plan.storage.database.queries.containers.ContainerFetchQueries;
|
||||
import com.djrapitops.plan.storage.file.PlanFiles;
|
||||
import com.djrapitops.plan.utilities.java.Maps;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -340,8 +341,12 @@ public class ResponseFactory {
|
||||
|
||||
public Response badRequest(String errorMessage, String target) {
|
||||
return Response.builder()
|
||||
.setMimeType(MimeType.HTML)
|
||||
.setContent("400 Bad Request: " + errorMessage + " (when requesting '" + target + "')")
|
||||
.setMimeType(MimeType.JSON)
|
||||
.setJSONContent(Maps.builder(String.class, Object.class)
|
||||
.put("status", 400)
|
||||
.put("error", errorMessage)
|
||||
.put("requestedTarget", target)
|
||||
.build())
|
||||
.setStatus(400)
|
||||
.build();
|
||||
}
|
||||
|
@ -21,12 +21,12 @@ import com.djrapitops.plan.delivery.web.ResolverSvc;
|
||||
import com.djrapitops.plan.delivery.web.resolver.NoAuthResolver;
|
||||
import com.djrapitops.plan.delivery.web.resolver.Resolver;
|
||||
import com.djrapitops.plan.delivery.web.resolver.Response;
|
||||
import com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException;
|
||||
import com.djrapitops.plan.delivery.web.resolver.request.Request;
|
||||
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
||||
import com.djrapitops.plan.delivery.webserver.resolver.*;
|
||||
import com.djrapitops.plan.delivery.webserver.resolver.json.RootJSONResolver;
|
||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||
import com.djrapitops.plan.exceptions.connection.BadRequestException;
|
||||
import com.djrapitops.plan.exceptions.connection.ForbiddenException;
|
||||
import com.djrapitops.plan.exceptions.connection.NotFoundException;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
|
@ -19,11 +19,11 @@ package com.djrapitops.plan.delivery.webserver.resolver.json;
|
||||
import com.djrapitops.plan.delivery.rendering.json.graphs.GraphJSONCreator;
|
||||
import com.djrapitops.plan.delivery.web.resolver.Resolver;
|
||||
import com.djrapitops.plan.delivery.web.resolver.Response;
|
||||
import com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException;
|
||||
import com.djrapitops.plan.delivery.web.resolver.request.Request;
|
||||
import com.djrapitops.plan.delivery.web.resolver.request.WebUser;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||
import com.djrapitops.plan.exceptions.connection.BadRequestException;
|
||||
import com.djrapitops.plan.identification.Identifiers;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -16,8 +16,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.identification;
|
||||
|
||||
import com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException;
|
||||
import com.djrapitops.plan.delivery.web.resolver.request.Request;
|
||||
import com.djrapitops.plan.exceptions.connection.BadRequestException;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.UserIdentifierQueries;
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan.delivery.webserver;
|
||||
|
||||
import com.djrapitops.plan.exceptions.connection.BadRequestException;
|
||||
import com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException;
|
||||
import com.djrapitops.plan.exceptions.connection.ForbiddenException;
|
||||
import com.djrapitops.plan.exceptions.connection.NotFoundException;
|
||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||
|
Loading…
Reference in New Issue
Block a user