-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.js
More file actions
executable file
·79 lines (72 loc) · 1.96 KB
/
errors.js
File metadata and controls
executable file
·79 lines (72 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// @flow
import type { FlowRequestTypes } from './types';
import stream from 'getstream';
export const handleError = (
error: Error,
type: FlowRequestTypes,
detail: Object,
) => {
console.warn(error);
alert(getErrorMessage(error, type, detail));
};
export const getErrorMessage = (
error: Error,
type: FlowRequestTypes,
detail: Object,
): string => {
console.warn(error);
if (!(error instanceof stream.errors.StreamApiError)) {
return fallbackErrorMessage(error, type, detail);
}
const response = error.response;
if (!response.statusCode || !response.body || !response.body.detail) {
return fallbackErrorMessage(error, type, detail);
}
const statusCode = response.statusCode;
const text = response.body.detail;
if (statusCode >= 400 && statusCode < 500) {
return text;
} else if (statusCode >= 500 && statusCode < 600) {
return text;
}
return fallbackErrorMessage(error, type, detail);
};
export const fallbackErrorMessage = (
error: Error,
type: FlowRequestTypes,
detail: Object,
): string => {
let text = 'Something went wrong';
let suffix = '';
switch (type) {
case 'get-user-info':
text += ' when loading user info';
break;
case 'get-feed':
text += ' when loading the feed';
break;
case 'get-feed-next-page':
text += ' when loading the next page of the feed';
break;
case 'get-notification-counts':
text += ' when loading your unread notification counts';
break;
case 'upload-image':
text += ' when uploading your image';
suffix = ' If it is, the image is probably too big';
break;
case 'add-activity':
text += ' when submitting your post';
break;
case 'add-reaction':
text += ' when submitting your ' + detail.kind;
break;
case 'delete-reaction':
text += ' when removing your ' + detail.kind;
break;
default:
break;
}
text += '. Is your internet working?' + suffix;
return text;
};