I don't use a CH32, and this may not be related to your problems, but-
unless you are planning to always write to addresses that start at a page boundary (doesn't appear to be so), I would think you would have to backup any preceding partial page before the page erase, then restore the partial page in the process of writing the new data.
8 bytes per page as an example-
write 4 bytes [0,1,2,3] to address 0-
[xxxxxxxx] erase page at address (0 bitand ~(8-1)) = 0
[0123xxxx] write data at address 0
write 4 bytes [4,5,6,7] to address 4-
[xxxxxxxx] erase page at address (4 bitand ~(8-1)) = 0
[xxxx4567] write data at address 4
the previous 4 bytes are now gone
resulting in unsuccessful writes or data corruption
Since you have multiple reasons for failure, you may want to return more values than 0 or 1 to narrow down what in particular is failing in your function. Enums of course work good for that kind of thing.