Commit 661d4b54 authored by Martin Santangelo's avatar Martin Santangelo

(feat) handle 403 responses on channels service

import apiService from "./api.service";
import apiService, { isApiForbidden } from "./api.service";
import UserModel from "../../channel/UserModel";
import { abort } from "../helpers/abortableFetch";
......@@ -42,6 +42,7 @@ class ChannelsService {
if (response.channel) {
const urn = `urn:channels:${guid}`;
if (channel) {
channel.update(response.channel);
} else {
......@@ -55,16 +56,38 @@ class ChannelsService {
throw new Error('No channel response');
}
} catch (err) {
console.log(err)
// if the server response is a 403
if (isApiForbidden(err)) {
// remove the permissions to force the UI update\
if (channel) {
channel.setPermissions({permissions:[]});
}
// remove it from local storage
this.removeFromCache(channel);
return;
}
throw err;
}
}
/**
* Save to cache
* @param {UserModel} channel
*/
async save(channel) {
// add urn to channel
channel.urn = `urn:channels:${channel.guid}`;
entitiesStorage.save(channel);
}
/**
* Remove from cache
* @param {UserModel} channel
*/
removeFromCache(channel) {
const urn = `urn:channels:${channel.guid}`;
entitiesStorage.remove( urn );
}
}
export default new ChannelsService();
\ No newline at end of file
// @flow
import _ from 'lodash';
import apiService, { isApiForbidden, ApiError } from "./api.service";
import apiService, { isApiForbidden } from "./api.service";
import sessionService from "./session.service";
import blockListService from "./block-list.service";
import GroupModel from "../../groups/GroupModel";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment