'use strict';

angular.module('app')
    .service('$error', ['$mdDialog', function ($mdDialog) {
        let self = this;

        function extractMessage(error) {
            if (typeof error === 'string') {
                return error;
            } else if (error.message) {
                return error.message;
            } else {
                try {
                    return JSON.stringify(error);
                } catch (e) {
                    return 'Unknown error.';
                }
            }
        }

        self.show = function (error) {
            let dialog = $mdDialog.alert()
                .title('Ups, something went wrong!')
                .textContent(extractMessage(error))
                .ok('OK');

            $mdDialog.show(dialog);
        };

    }]);

@@ -116,16 +116,140 @@
  this;%0A%0A
+        const TITLES = %5B%0A            'Ups, something went wrong!',%0A            'Oh no, this shouldn%5C't happen.'%0A        %5D;%0A%0A
         
@@ -754,36 +754,24 @@
 tle(
-'Ups, something went wrong!'
+_.sample(TITLES)
 )%0A  

Add some random error messages.