mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-12 15:02:25 -05:00
b795579ca0
[web] send OError info and OError tags/cause tracebacks to sentry GitOrigin-RevId: 0544768ca16fcafb63ec6116a573e83302cdbdd3
75 lines
2.2 KiB
JavaScript
75 lines
2.2 KiB
JavaScript
/* 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
|
|
* DS207: Consider shorter variations of null checks
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
*/
|
|
import { captureException } from '../infrastructure/error-reporter'
|
|
|
|
const app = angular.module('ErrorCatcher', [])
|
|
const UNHANDLED_REJECTION_ERR_MSG = 'Possibly unhandled rejection: canceled'
|
|
|
|
app.config([
|
|
'$provide',
|
|
$provide =>
|
|
$provide.decorator('$exceptionHandler', [
|
|
'$log',
|
|
'$delegate',
|
|
($log, $delegate) =>
|
|
function (exception, cause) {
|
|
if (
|
|
exception === UNHANDLED_REJECTION_ERR_MSG &&
|
|
cause === undefined
|
|
) {
|
|
return
|
|
}
|
|
|
|
captureException(exception, {
|
|
tags: {
|
|
handler: 'angular-exception-handler',
|
|
},
|
|
})
|
|
|
|
return $delegate(exception, cause)
|
|
},
|
|
]),
|
|
])
|
|
|
|
// Interceptor to check auth failures in all $http requests
|
|
// http://bahmutov.calepin.co/catch-all-errors-in-angular-app.html
|
|
|
|
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'
|
|
}
|
|
}
|
|
// pass the response back to the original requester
|
|
return $q.reject(response)
|
|
},
|
|
}))
|
|
|
|
app.config([
|
|
'$httpProvider',
|
|
$httpProvider =>
|
|
$httpProvider.interceptors.push('unAuthHttpResponseInterceptor'),
|
|
])
|