2018-11-05 05:06:39 -05:00
|
|
|
/* eslint-disable
|
|
|
|
max-len,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
2020-05-19 05:02:56 -04:00
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-12-03 08:58:46 -05:00
|
|
|
import { captureException } from '../infrastructure/error-reporter'
|
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
const app = angular.module('ErrorCatcher', [])
|
2018-11-22 05:55:10 -05:00
|
|
|
const UNHANDLED_REJECTION_ERR_MSG = 'Possibly unhandled rejection: canceled'
|
2018-11-05 05:06:39 -05:00
|
|
|
|
|
|
|
app.config([
|
|
|
|
'$provide',
|
|
|
|
$provide =>
|
|
|
|
$provide.decorator('$exceptionHandler', [
|
|
|
|
'$log',
|
|
|
|
'$delegate',
|
|
|
|
($log, $delegate) =>
|
2021-04-14 09:17:21 -04:00
|
|
|
function (exception, cause) {
|
2018-11-22 05:55:10 -05:00
|
|
|
if (
|
|
|
|
exception === UNHANDLED_REJECTION_ERR_MSG &&
|
|
|
|
cause === undefined
|
|
|
|
) {
|
|
|
|
return
|
|
|
|
}
|
2020-12-03 08:58:46 -05:00
|
|
|
|
2022-07-28 10:38:55 -04:00
|
|
|
captureException(exception, {
|
|
|
|
tags: {
|
|
|
|
handler: 'angular-exception-handler',
|
|
|
|
},
|
2020-12-03 08:58:46 -05:00
|
|
|
})
|
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
return $delegate(exception, cause)
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
|
|
|
]),
|
2018-11-05 05:06:39 -05:00
|
|
|
])
|
|
|
|
|
|
|
|
// Interceptor to check auth failures in all $http requests
|
|
|
|
// http://bahmutov.calepin.co/catch-all-errors-in-angular-app.html
|
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
app.factory('unAuthHttpResponseInterceptor', ($q, $location) => ({
|
|
|
|
responseError(response) {
|
|
|
|
// redirect any unauthorised or forbidden responses back to /login
|
|
|
|
//
|
|
|
|
// set disableAutoLoginRedirect:true in the http request config
|
|
|
|
// to disable this behaviour
|
|
|
|
if (
|
|
|
|
[401, 403].includes(response.status) &&
|
|
|
|
!(response.config != null
|
|
|
|
? response.config.disableAutoLoginRedirect
|
|
|
|
: undefined)
|
|
|
|
) {
|
|
|
|
// for /project urls set the ?redir parameter to come back here
|
|
|
|
// otherwise just go to the login page
|
|
|
|
if (window.location.pathname.match(/^\/project/)) {
|
|
|
|
window.location = `/login?redir=${encodeURI(window.location.pathname)}`
|
|
|
|
} else {
|
|
|
|
window.location = '/login'
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
// pass the response back to the original requester
|
|
|
|
return $q.reject(response)
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-07-16 05:13:18 -04:00
|
|
|
}))
|
2018-11-05 05:06:39 -05:00
|
|
|
|
|
|
|
app.config([
|
|
|
|
'$httpProvider',
|
|
|
|
$httpProvider =>
|
2021-04-27 03:52:58 -04:00
|
|
|
$httpProvider.interceptors.push('unAuthHttpResponseInterceptor'),
|
2018-11-05 05:06:39 -05:00
|
|
|
])
|