I have a method where I am sending values to my backend, so far saving works, now I want to make an error handling. But when I try to console.log my error I am getting back an undefined. I tried different things like consoling the error directly or first assigning it to a const, but it always returns an undefined. Could someone look at it and tell me where my error is?
uploadFile(files: FileList | null): void {
const documents = this.documentArray;
if (files) {
const file = files.item(0);
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
documents.filename = file.name;
documents.base64 = "reader.result.slice(28).toString()";
documents.documentType = this.form.controls.dokumentType.value;
this.api.saveDocument({body:
documents}).subscribe((res) =>{
const data = res
console.log("Here is your data: " + data)
}, (error: HttpErrorResponse) => {
const err = error
console.error("Here is your error: " + err.status)
})
};
}