Parcourir la source

Improve error handling in bufferToUrl filter (#99)

If `buffer` is falsy, log an error and abort. Otherwise, we'll get generic `InvalidArgument` exceptions.
Danilo Bargen il y a 8 ans
Parent
commit
03dc35c26d
1 fichiers modifiés avec 6 ajouts et 1 suppressions
  1. 6 1
      src/filters.ts

+ 6 - 1
src/filters.ts

@@ -178,8 +178,13 @@ angular.module('3ema.filters', [])
         return padLeft + left + ':' + padRight + right;
     };
 })
-.filter('bufferToUrl', ['$sce', function($sce) {
+.filter('bufferToUrl', ['$sce', '$log', function($sce, $log) {
+    const logTag = '[filters.bufferToUrl]';
     return function(buffer: ArrayBuffer, mimeType) {
+        if (!buffer) {
+            $log.error(logTag, 'Could not apply bufferToUrl filter: buffer is', buffer);
+            return '';
+        }
         let binary = '';
         const bytes = new Uint8Array(buffer);
         const len = bytes.byteLength;