What do I need to return in backend response to inform Filepond about error which was caused by one of uploaded files? I can't find any information about specific template in docs. What structure should be adapted to returned json?
I just checked the docs and indeed this might need some additional explanation.
It works like this:
If everything is fine, your server responds with an http status between 200 and 300
If something is wrong it responds with a status between 400 and 500
You can then use the onload and onerror hooks on the process end point to parse the server response (if necessary).
@rikschennink
Thanks for your response!
I have another question. Lets say, that I'm uploading 3 files. One is uploaded correctly, one is too big, and the last one has invalid MIME type. It is possible to display proper error message near proper file?
Yes, you can of course validate this on the client using the validation plugins. Validation again on the server is wise.
You can return the matching 4xx status code, and then if necessary parse the response (you could return a custom response message or code).
To customize the message for each different error you can set labelFileProcessingError to a function and return a label based on the server error received.
labelFileProcessingError: function(serverError) { return 'my error message'; }
@rikschennink
Thank you again! :)
I'll close this issue, and will open it again when I will have some more problems.
@rikschennink
I implemented my backend to return 400 code with json in body with structure like this (when error occurs):
[
"status": "error",
"message": "custom message"
]
How to get value from "message"?
While using below code, the response variable does not contain my custom message. The body within this variable is a string with "Bad Request" value.
labelFileProcessingError={(response) => {
console.log(response);
}
Structure of the response variable:
{
"type": "error",
"code": 400,
"body": "Bad Request",
"headers": "...."
}
You can use the onerror callback on the server.process object to filter the server response.
Was wondering the same about what status code should the server return in case of error . I think it's still not documented on the docs.
4**
I now know from reading your previous comment, my point is that it's probably better to just put in the docs, maybe in the server page ?
Aha. The docs are on GH, feel free to submit a PR
https://github.com/pqina/filepond-docs
Most helpful comment
@rikschennink
I implemented my backend to return 400 code with json in body with structure like this (when error occurs):
How to get value from "message"?
While using below code, the
responsevariable does not contain my custom message. Thebodywithin this variable is a string with "Bad Request" value.Structure of the
responsevariable: