Skip to content

Commit

Permalink
fix: #48 sentry log not capture error, add logger util in all apps (#169
Browse files Browse the repository at this point in the history
)

* fix: #48 sentry log not capture error, add logger util in all apps

* fix: #48 fix test file

* fix: #48 move logger utils to root

* fix: #48 resolve conflict
  • Loading branch information
vuhuucuong authored Feb 12, 2020
1 parent d580eeb commit d8d4f01
Show file tree
Hide file tree
Showing 62 changed files with 177 additions and 101 deletions.
10 changes: 6 additions & 4 deletions packages/aml-checklist/src/components/hocs/error-boundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ export class ErrorBoundary extends React.Component<ErrorProps, ErrorState> {
type: 'COMPONENT',
message: errorMessages.DEFAULT_COMPONENT_ERROR,
})
Sentry.withScope(scope => {
scope.setExtras(info)
Sentry.captureException(error)
})
if (process.env.NODE_ENV === 'production') {
Sentry.withScope(scope => {
scope.setExtras(info)
Sentry.captureException(error)
})
}
console.error('ERROR BOUNDARY CAUGHT', error.message, info)
}

Expand Down
5 changes: 3 additions & 2 deletions packages/aml-checklist/src/sagas/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ActionTypes from '@/constants/action-types'
import { authLoginSuccess, authLoginFailure } from '@/actions/auth'
import { LoginParams, LoginSession, setUserSession, removeSession, redirectToLogout } from '@reapit/cognito-auth'
import { COOKIE_SESSION_KEY_AML_APP } from '../constants/api'
import { logger } from 'logger'

export const doLogin = function*({ data }: Action<LoginParams>) {
try {
Expand All @@ -15,7 +16,7 @@ export const doLogin = function*({ data }: Action<LoginParams>) {
yield put(authLoginFailure())
}
} catch (err) {
console.error(err.message)
logger(err)
yield put(authLoginFailure())
}
}
Expand All @@ -25,7 +26,7 @@ export const doLogout = function*() {
yield call(removeSession, COOKIE_SESSION_KEY_AML_APP)
yield call(redirectToLogout, process.env.COGNITO_CLIENT_ID_AML_APP as string, `${window.location.origin}/login`)
} catch (err) {
console.error(err.message)
logger(err)
}
}

Expand Down
26 changes: 15 additions & 11 deletions packages/aml-checklist/src/sagas/checklist-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { handlePepSearchStatus } from '@/utils/pep-search'
import dayjs from 'dayjs'
import { ID_STATUS } from '@/components/ui/modal/modal'
import { changeTimeZoneLocalForIdentityCheck, changeTimeZoneUTCForIdentityCheck } from '@/utils/datetime'
import { logger } from 'logger'

export const fetchChecklist = async ({ id, headers }) => {
try {
Expand All @@ -36,7 +37,7 @@ export const fetchChecklist = async ({ id, headers }) => {
})
return response
} catch (err) {
console.error(err.message)
logger(err)
return err
}
}
Expand All @@ -57,7 +58,7 @@ export const fetchIdentityCheck = async ({ contactId, headers }) => {
}
return newResponse?._embedded?.[0] || null
} catch (err) {
console.error(err.message)
logger(err)
return err
}
}
Expand All @@ -77,7 +78,7 @@ export const updateChecklist = async ({ contact, headers }) => {
})
return response
} catch (err) {
console.error(err.message)
logger(err)
return err
}
}
Expand All @@ -101,7 +102,7 @@ export const uploadImage = async ({ name, imageData, headers }) => {
})
return response
} catch (err) {
console.error(err.message)
logger(err)
return err
}
}
Expand All @@ -122,7 +123,7 @@ export const updateIdentityCheck = async ({ identityChecks, headers }) => {
})
return response
} catch (err) {
console.error(err)
logger(err)
return err
}
}
Expand All @@ -139,7 +140,7 @@ export const createIdentityCheck = async ({ identityChecks, headers }) => {
})
return response
} catch (err) {
console.error(err)
logger(err)
return err
}
}
Expand All @@ -155,6 +156,7 @@ export const fetchInitialData = function*({ data: id }) {
yield put(checklistDetailReceiveContact(contact))
yield put(checklistDetailReceiveIdentityCheck(identityChecks))
} catch (err) {
logger(err)
yield put(
errorThrownServer({
type: 'SERVER',
Expand Down Expand Up @@ -192,7 +194,7 @@ export const onUpdateChecklist = function*({
}
}
} catch (err) {
console.error(err.message)
logger(err)
yield put(
errorThrownServer({
type: 'SERVER',
Expand Down Expand Up @@ -256,7 +258,7 @@ export const onUpdateAddressHistory = function*({
}
}
} catch (err) {
console.error(err.message)
logger(err)
yield put(
errorThrownServer({
type: 'SERVER',
Expand Down Expand Up @@ -316,7 +318,7 @@ export const onUpdateDeclarationAndRisk = function*({
}
}
} catch (err) {
console.error(err.message)
logger(err)
yield put(
errorThrownServer({
type: 'SERVER',
Expand All @@ -340,7 +342,7 @@ export const fetchDataPepSearch = async ({ name, headers }) => {
})
return result
} catch (err) {
console.error(err.message)
logger(err)
return err
}
}
Expand All @@ -358,7 +360,7 @@ export const pepSearch = function*({ data }) {
yield put(checklistDetailShowModal(data.nextSection))
}
} catch (err) {
console.error(err.message)
logger(err)
yield put(
errorThrownServer({
type: 'SERVER',
Expand Down Expand Up @@ -436,6 +438,7 @@ export const updatePrimaryId = function*({ data: { nextSection, identityChecks }
yield put(checklistDetailHideModal())
}
} catch (err) {
logger(err)
const result: ErrorData = {
type: 'SERVER',
message: errorMessages.DEFAULT_SERVER_ERROR,
Expand Down Expand Up @@ -500,6 +503,7 @@ export const updateSecondaryId = function*({
yield put(checklistDetailHideModal())
}
} catch (err) {
logger(err)
const result: ErrorData = {
type: 'SERVER',
message: errorMessages.DEFAULT_SERVER_ERROR,
Expand Down
2 changes: 2 additions & 0 deletions packages/aml-checklist/src/sagas/identity-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { initAuthorizedRequestHeaders } from '@/utils/api'
import { errorThrownServer } from '../actions/error'
import { identityTypesReceiveData, identityTypesRequestFailure } from '../actions/identity-types'
import errorMessages from '../constants/error-messages'
import { logger } from 'logger'

export const identityTypesDataFetch = function*() {
const headers = yield call(initAuthorizedRequestHeaders)
Expand All @@ -19,6 +20,7 @@ export const identityTypesDataFetch = function*() {
})
yield put(identityTypesReceiveData(response))
} catch (err) {
logger(err)
yield put(identityTypesRequestFailure())
yield put(
errorThrownServer({
Expand Down
2 changes: 2 additions & 0 deletions packages/aml-checklist/src/sagas/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { resultReceiveData, resultRequestDataFailure, ContactsParams } from '@/a
import { queryParams } from '@/utils/query-params'
import { CONTACTS_PER_PAGE } from '@/constants/paginator'
import { initAuthorizedRequestHeaders } from '@/utils/api'
import { logger } from 'logger'

export const resultFetch = function*(params: Action<ContactsParams>) {
try {
Expand All @@ -21,6 +22,7 @@ export const resultFetch = function*(params: Action<ContactsParams>) {
})
yield put(resultReceiveData(responseContacts))
} catch (err) {
logger(err)
yield put(resultRequestDataFailure())
yield put(
errorThrownServer({
Expand Down
2 changes: 1 addition & 1 deletion packages/aml-checklist/src/tests/badges/badge-branches.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/aml-checklist/src/tests/badges/badge-lines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion packages/aml-checklist/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"@/*": ["src/*"],
"@reapit/cognito-auth": ["../cognito-auth/src"],
"@reapit/elements": ["../elements/src"],
"@reapit/foundations-ts-definitions": ["./src/types/api-2020-01-31"]
"@reapit/foundations-ts-definitions": ["./src/types/api-2020-01-31"],
"logger": ["../../scripts/logger/sentry-logger.ts"]
}
},
"include": ["src"]
Expand Down
10 changes: 6 additions & 4 deletions packages/geo-diary/src/components/hocs/error-boundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ export class ErrorBoundary extends React.Component<ErrorProps, ErrorState> {
type: 'COMPONENT',
message: errorMessages.DEFAULT_COMPONENT_ERROR,
})
Sentry.withScope(scope => {
scope.setExtras(info)
Sentry.captureException(error)
})
if (process.env.NODE_ENV === 'production') {
Sentry.withScope(scope => {
scope.setExtras(info)
Sentry.captureException(error)
})
}
console.error('ERROR BOUNDARY CAUGHT', error.message, info)
}

Expand Down
5 changes: 3 additions & 2 deletions packages/geo-diary/src/sagas/appointment-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { AppointmentDetailRequestParams } from '@/actions/appointment-detail'
import { selectAppointmentDetail } from '@/selectors/appointment-detail'
import { selectAppointmentsFilterTime, selectAppointmentWithId } from '@/selectors/appointments'
import { fetchAppointment, updateAppointment } from './api'
import { logger } from 'logger'

export const appointmentDetailDataFetch = function*({ data: { id } }: Action<AppointmentDetailRequestParams>) {
yield put(appointmentDetailShowModal())
Expand Down Expand Up @@ -48,7 +49,7 @@ export const appointmentDetailDataFetch = function*({ data: { id } }: Action<App
yield put(appointmentDetailRequestDataFailure())
}
} catch (err) {
console.error(err.message)
logger(err)
yield put(appointmentDetailRequestDataFailure())
yield put(
errorThrownServer({
Expand Down Expand Up @@ -78,7 +79,7 @@ export const cancelAppointmentRequest = function*() {
yield put(appointmentsRequestData({ time: filterTime }))
}
} catch (error) {
console.error(error.message)
logger(error)
yield put(
errorThrownServer({
type: 'SERVER',
Expand Down
3 changes: 2 additions & 1 deletion packages/geo-diary/src/sagas/appointments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { initAuthorizedRequestHeaders } from '@/utils/api'
import { sortAppoinmentsByStartTime } from '@/utils/sort-appointments-by-start-time'
import utc from 'dayjs/plugin/utc'
import { fetchAppointmentMetadata } from './api'
import { logger } from 'logger'

dayjs.extend(utc)

Expand Down Expand Up @@ -134,7 +135,7 @@ export const appointmentsDataFetch = function*({ data: { time } }: Action<Appoin
yield put(appointmentsRequestDataFailure())
}
} catch (err) {
console.error(err.message)
logger(err)
yield put(
errorThrownServer({
type: 'SERVER',
Expand Down
5 changes: 3 additions & 2 deletions packages/geo-diary/src/sagas/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { authLoginSuccess, authLoginFailure } from '@/actions/auth'
import { LoginParams, LoginSession, setUserSession, removeSession, redirectToLogout } from '@reapit/cognito-auth'
import { COOKIE_SESSION_KEY_GEO_DIARY } from '../constants/api'
import store from '@/core/store'
import { logger } from 'logger'

export const doLogin = function*({ data }: Action<LoginParams>) {
try {
Expand All @@ -16,7 +17,7 @@ export const doLogin = function*({ data }: Action<LoginParams>) {
yield put(authLoginFailure())
}
} catch (err) {
console.error(err.message)
logger(err)
yield put(authLoginFailure())
}
}
Expand All @@ -27,7 +28,7 @@ export const doLogout = function*() {
yield call(removeSession, COOKIE_SESSION_KEY_GEO_DIARY)
yield call(redirectToLogout, process.env.COGNITO_CLIENT_ID_GEO_DIARY as string, `${window.location.origin}/login`)
} catch (err) {
console.error(err.message)
logger(err)
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/geo-diary/src/sagas/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ActionTypes from '../constants/action-types'
import { errorThrownServer } from '../actions/error'
import errorMessages from '../constants/error-messages'
import { Action } from '@/types/core'
import { logger } from 'logger'

export const homeDataFetch = function*() {
yield put(homeLoading(true))
Expand All @@ -13,7 +14,7 @@ export const homeDataFetch = function*() {

yield put(homeReceiveData({ data: response }))
} catch (err) {
console.error(err.message)
logger(err)
yield put(homeRequestDataFailure())
yield put(
errorThrownServer({
Expand Down
3 changes: 2 additions & 1 deletion packages/geo-diary/src/sagas/next-appointment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { nextAppointmentValidateSuccess, nextAppointmentClear } from '@/actions/
import { selectUserCode } from '@/selectors/auth'
import { Action } from '@/types/core'
import { getLoggedInUser } from '../components/common/appointment-detail/appointment-detail'
import { logger } from 'logger'

type Position = {
lat: number
Expand Down Expand Up @@ -101,7 +102,7 @@ export const validateNextAppointment = function*({ data: travelMode }: Action<st
)
}
} catch (err) {
console.error(err.message)
logger(err)
yield put(nextAppointmentClear())
}
} else {
Expand Down
Loading

0 comments on commit d8d4f01

Please sign in to comment.