diff options
author | crupest <crupest@outlook.com> | 2020-08-07 23:51:29 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-08-07 23:51:29 +0800 |
commit | 151105f387c65f2285f61f8e492ad06734ec9f64 (patch) | |
tree | c2186add6890e2a5af233345b08af065cada4d68 /Timeline/ClientApp/src/app/http | |
parent | bace0870ee294e44d0112ba49de12b27fa3c0a31 (diff) | |
download | timeline-151105f387c65f2285f61f8e492ad06734ec9f64.tar.gz timeline-151105f387c65f2285f61f8e492ad06734ec9f64.tar.bz2 timeline-151105f387c65f2285f61f8e492ad06734ec9f64.zip |
...
Diffstat (limited to 'Timeline/ClientApp/src/app/http')
-rw-r--r-- | Timeline/ClientApp/src/app/http/common.ts | 20 | ||||
-rw-r--r-- | Timeline/ClientApp/src/app/http/timeline.ts | 3 |
2 files changed, 23 insertions, 0 deletions
diff --git a/Timeline/ClientApp/src/app/http/common.ts b/Timeline/ClientApp/src/app/http/common.ts index 3c2f2ba6..8b082d1f 100644 --- a/Timeline/ClientApp/src/app/http/common.ts +++ b/Timeline/ClientApp/src/app/http/common.ts @@ -45,6 +45,12 @@ export class HttpNetworkError extends Error { }
}
+export class HttpForbiddenError extends Error {
+ constructor(public innerError?: AxiosError) {
+ super();
+ }
+}
+
export class NotModified {}
export interface BlobWithEtag {
@@ -119,6 +125,20 @@ export function convertToNetworkError( }
}
+export function convertToForbiddenError(
+ error: AxiosError<CommonErrorResponse>
+): never {
+ if (
+ error.isAxiosError &&
+ error.response != null &&
+ (error.response.status == 403 || error.response.status == 403)
+ ) {
+ throw new HttpForbiddenError(error);
+ } else {
+ throw error;
+ }
+}
+
export function extractDataOrConvert304ToNotModified<T>(
res: AxiosResponse<T>
): T | NotModified {
diff --git a/Timeline/ClientApp/src/app/http/timeline.ts b/Timeline/ClientApp/src/app/http/timeline.ts index bfe0d1ad..0b219787 100644 --- a/Timeline/ClientApp/src/app/http/timeline.ts +++ b/Timeline/ClientApp/src/app/http/timeline.ts @@ -11,6 +11,7 @@ import { BlobWithEtag,
NotModified,
convertToBlobWithEtagOrNotModified,
+ convertToForbiddenError,
} from './common';
import { HttpUser } from './user';
@@ -441,6 +442,8 @@ export class HttpTimelineClient implements IHttpTimelineClient { return axios
.get<RawTimelineGenericPostInfo[]>(url)
.then(extractResponseData)
+ .catch(convertToIfStatusCodeIs(404, HttpTimelineNotExistError))
+ .catch(convertToForbiddenError)
.catch(convertToNetworkError)
.then((rawPosts) =>
rawPosts.map((raw) => processRawTimelinePostInfo(raw))
|