{"record":{"id":"40b7054d508d3852","repo":"halo-dev/halo","slug":"required-url-is-missing","errorCode":null,"errorMessage":"Required url is missing.","messagePattern":"Required url is missing\\.","errorType":"http","errorClass":"ServerWebInputException","httpStatus":400,"severity":"warning","filePath":"application/src/main/java/run/halo/app/core/attachment/endpoint/AttachmentEndpoint.java","lineNumber":138,"sourceCode":"    /**\n     * Request payload for creating an attachment from a remote URL.\n     *\n     * @param url remote file URL to transfer into storage\n     * @param policyName storage policy {@code metadata.name}\n     * @param groupName attachment group {@code metadata.name}\n     * @param filename custom file name\n     */\n    public record UploadFromUrlRequest(\n            @Schema(requiredMode = REQUIRED) URL url,\n\n            @Schema(requiredMode = REQUIRED) String policyName,\n\n            String groupName,\n\n            String filename) {\n        public UploadFromUrlRequest {\n            if (Objects.isNull(url)) {\n                throw new ServerWebInputException(\"Required url is missing.\");\n            }\n\n            if (!StringUtils.hasText(policyName)) {\n                throw new ServerWebInputException(\"Policy name must not be blank\");\n            }\n        }\n    }\n\n    /** Multipart payload for uploading an attachment. */\n    @Schema(types = \"object\")\n    public interface IUploadRequest {\n\n        /** Attachment file. */\n        @Schema(requiredMode = REQUIRED)\n        FilePart getFile();\n\n        /** Storage policy {@code metadata.name}. */\n        @Schema(requiredMode = REQUIRED)","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/halo-dev/halo/blob/d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8/application/src/main/java/run/halo/app/core/attachment/endpoint/AttachmentEndpoint.java#L120-L156","documentation":"UploadFromUrlRequest is a record whose compact constructor validates required fields. It throws ServerWebInputException (HTTP 400) 'Required url is missing.' when the url component is null. The url field is annotated @Schema(requiredMode = REQUIRED), so the guard enforces that contract at construction time (i.e. when Spring binds the request body).","triggerScenarios":"POST to the upload-from-url attachment endpoint with a JSON body that omits \"url\", sends url:null, or sends a value that cannot be bound to java.net.URL (which may fail earlier in binding).","commonSituations":"Client form bug that doesn't send the url field; a UI that lets the user submit before entering a URL; integration code constructing the body from optional fields.","solutions":["Include a non-null url in the JSON body of the upload-from-url request.","Disable the submit control on the client until a URL is entered.","If invoking the endpoint programmatically, assert url != null before serializing the body."],"exampleFix":"// before\n{ \"policyName\": \"default\" } // 400: url missing\n\n// after\n{ \"url\": \"https://example.com/file.png\", \"policyName\": \"default\" }","handlingStrategy":"validation","validationCode":"if (url == null) {\n    return Mono.error(new ServerWebInputException(\"Required url is missing.\"));\n}\n// build UploadFromUrlRequest(url, policyName, groupName, filename)","typeGuard":"static boolean hasUrl(URL url) { return url != null; }","tryCatchPattern":null,"preventionTips":["Make the url field required in the UI form and disable submit until filled.","When constructing the body programmatically, assert url != null first.","Validate that the string parses to a real URL before sending."],"tags":["validation","attachment","upload","http-400","required-field","record-constructor"],"backgroundTag":null,"analyzedSha":"d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8","analyzedAt":"2026-08-14T00:18:38.915Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}