{"record":{"id":"dbd04aafec095c7e","repo":"halo-dev/halo","slug":"required-url-is-missing-dbd04a","errorCode":null,"errorMessage":"Required url is missing.","messagePattern":"Required url is missing\\.","errorType":"validation","errorClass":"ServerWebInputException","httpStatus":400,"severity":"error","filePath":"application/src/main/java/run/halo/app/core/endpoint/uc/AttachmentUcEndpoint.java","lineNumber":315,"sourceCode":"\n    @Override\n    public GroupVersion groupVersion() {\n        return GroupVersion.parseAPIVersion(\"uc.api.storage.halo.run/v1alpha1\");\n    }\n\n    /**\n     * User-center request payload for uploading from a URL.\n     *\n     * @param url remote file URL to transfer into user-center storage\n     * @param filename custom file name\n     */\n    @Schema(name = \"UcUploadFromUrlRequest\")\n    public record UploadFromUrlRequest(\n            @Schema(requiredMode = REQUIRED) URL url, String filename) {\n\n        public UploadFromUrlRequest {\n            if (Objects.isNull(url)) {\n                throw new ServerWebInputException(\"Required url is missing.\");\n            }\n        }\n    }\n\n    /**\n     * Multipart payload for uploading a post attachment.\n     *\n     * @param file attachment data\n     * @param postName post {@code metadata.name}\n     * @param singlePageName single page {@code metadata.name}\n     */\n    @Schema(types = \"object\")\n    public record PostAttachmentRequest(\n            @Schema(requiredMode = REQUIRED) FilePart file,\n\n            @Schema(requiredMode = NOT_REQUIRED) String postName,\n\n            @Schema(requiredMode = NOT_REQUIRED) String singlePageName) {","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/halo-dev/halo/blob/d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8/application/src/main/java/run/halo/app/core/endpoint/uc/AttachmentUcEndpoint.java#L297-L333","documentation":"Thrown as a ServerWebInputException (HTTP 400) from the UploadFromUrlRequest compact constructor (user-center attachment endpoint) when the 'url' field is null. The record's URL field is declared required; the compact constructor enforces non-null because Spring may bind an absent body to a null url rather than rejecting binding.","triggerScenarios":"POST to the user-center upload-from-URL endpoint (AttachmentUcEndpoint) with a JSON body that omits 'url', sends url:null, or sends an empty body. The record constructor runs and Objects.isNull(url) is true.","commonSituations":"Frontend submitted the form before entering a URL; client serialized the field with the wrong key; paste left the field empty; API test posted {} intentionally.","solutions":["Provide a non-null 'url' field in the request body, e.g. {\"url\":\"https://example.com/img.png\",\"filename\":\"img.png\"}.","Add client-side required-field validation on the URL input before submit.","Ensure the URL parses as java.net.URL (scheme + host present)."],"exampleFix":"// before:  {}\n// after:   { \"url\": \"https://example.com/photo.png\", \"filename\": \"photo.png\" }","handlingStrategy":"validation","validationCode":"// require a non-null, parseable URL before upload-from-URL\nif (url == null || url.isBlank()) {\n    showUserError(\"URL is required\");\n    return;\n}\ntry { new java.net.URL(url); } catch (Exception e) {\n    showUserError(\"Enter a valid URL\"); return;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make the URL field required in the upload-from-URL UI.","Validate scheme+host presence so java.net.URL can parse it."],"tags":["attachment","upload","validation","required-field","user-center"],"backgroundTag":null,"analyzedSha":"d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8","analyzedAt":"2026-08-14T00:18:38.915Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}