Skip to content

Commit 66f1e19

Browse files
committed
feat(e2e): seperated messages for fetch and decrypt errors
1 parent 923a8b9 commit 66f1e19

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

constants/messages.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
export const E2E_LINK_GENERATION_ERROR =
22
'Failed to generate E2E Link. Please try again later.'
33

4-
export const E2E_LINK_GENERATION_SUCCESS = 'E2E Link copied to your clipboard'
4+
export const E2E_LINK_GENERATION_SUCCESS = 'E2E encrypted diff link copied to your clipboard'
55

66
export const E2E_DATA_LOADING_INFO = 'Loading your end to end encrypted diff...'
77

88
export const E2E_DATA_DECRYPTING_INFO = 'Decrypting your diff on your browser...'
99

1010
export const E2E_DATA_FINALIZING_INFO = 'Diffing your data...'
1111

12-
export const E2E_DATA_ERROR =
13-
"We couldn't fetch/decrypt your diff. Please try again later."
12+
export const E2E_DATA_FETCH_ERROR =
13+
"We couldn't fetch your diff. Please try again later."
14+
15+
export const E2E_DATA_DECRYPTION_ERROR =
16+
"We couldn't decrypt your diff. Please check the link and try again."
1417

1518
export const E2E_DATA_NO_LONGER_AVAILABLE_ERROR =
16-
'Looks like your diff data is no longer available. Sorry for the inconvenience.'
19+
'Looks like the link has expired. Please check the link or generate a new one.'
1720

1821
export const LINK_COPY_SUCCESS = 'Link copied to your clipboard'
1922

pages/v2/diff.vue

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ import { getDecryptedText, getDepryctionKey } from '~/helpers/decrypt'
7373
import { v2DiffData } from '~/helpers/types'
7474
import {
7575
E2E_DATA_DECRYPTING_INFO,
76-
E2E_DATA_ERROR,
76+
E2E_DATA_DECRYPTION_ERROR,
77+
E2E_DATA_FETCH_ERROR,
7778
E2E_DATA_FINALIZING_INFO,
7879
E2E_DATA_LOADING_INFO,
7980
E2E_DATA_NO_LONGER_AVAILABLE_ERROR,
@@ -134,12 +135,20 @@ export default Vue.extend({
134135
},
135136
async getE2EData() {
136137
this.e2eDataStatusText = E2E_DATA_LOADING_INFO
138+
const url = new URL(window.location.href)
139+
const id = url.searchParams.get('id')
140+
const key = url.hash.replace(/^#/, '')
141+
let response = null;
142+
let data = null
143+
try {
144+
response = await fetch(`/api/getLink?id=${id}`)
145+
data = await response.json()
146+
} catch (error) {
147+
console.error(error)
148+
this.e2eDataStatusText = E2E_DATA_FETCH_ERROR
149+
return null
150+
}
137151
try {
138-
const url = new URL(window.location.href)
139-
const id = url.searchParams.get('id')
140-
const key = url.hash.replace(/^#/, '')
141-
const response = await fetch(`/api/getLink?id=${id}`)
142-
const data = await response.json()
143152
if (data.length === 0) {
144153
this.e2eDataStatusText = E2E_DATA_NO_LONGER_AVAILABLE_ERROR
145154
return null
@@ -157,7 +166,7 @@ export default Vue.extend({
157166
return decryptedData
158167
} catch (error) {
159168
console.error(error)
160-
this.e2eDataStatusText = E2E_DATA_ERROR
169+
this.e2eDataStatusText = E2E_DATA_DECRYPTION_ERROR
161170
return null
162171
}
163172
},

0 commit comments

Comments
 (0)