When an exception occurs and you catch the exception, you still need to return a result for the function. Initialize your variable files to contain an empty array and then return it after the try-catch-block, so it is always returned, even when an error occurs.