From f353dc2c419664bc8aa5523bad6d9af7025106ee Mon Sep 17 00:00:00 2001 From: Kevan Ahlquist Date: Sat, 19 Mar 2016 18:50:11 -0500 Subject: [PATCH] Add a global interceptor to catch 'conflict.' API responses. --- app/app.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/app.js b/app/app.js index 8ec6554ba..c83067df2 100644 --- a/app/app.js +++ b/app/app.js @@ -23,7 +23,7 @@ angular.module('dockerui', [ 'network', 'networks', 'volumes']) - .config(['$routeProvider', function ($routeProvider) { + .config(['$routeProvider', '$httpProvider', function ($routeProvider, $httpProvider) { 'use strict'; $routeProvider.when('/', { templateUrl: 'app/components/dashboard/dashboard.html', @@ -67,9 +67,25 @@ angular.module('dockerui', [ controller: 'EventsController' }); $routeProvider.otherwise({redirectTo: '/'}); + + // The Docker API likes to return plaintext errors, this catches them and disp + $httpProvider.interceptors.push(function() { + return { + 'response': function(response) { + if (typeof(response.data) === 'string' && response.data.startsWith('Conflict.')) { + $.gritter.add({ + title: 'Error', + text: response.data, + time: 10000 + }); + } + return response; + } + }; + }); }]) // This is your docker url that the api will use to make requests // You need to set this to the api endpoint without the port i.e. http://192.168.1.9 .constant('DOCKER_ENDPOINT', 'dockerapi') .constant('DOCKER_PORT', '') // Docker port, leave as an empty string if no port is requred. If you have a port, prefix it with a ':' i.e. :4243 - .constant('UI_VERSION', 'v0.9.0-beta'); + .constant('UI_VERSION', 'v0.9.0-beta'); \ No newline at end of file