1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 00:03:56 +00:00

handle server errors for attachment save

This commit is contained in:
Kyle Spearrin
2017-11-15 22:36:20 -05:00
parent d9f6607073
commit a166dc65b1
4 changed files with 30 additions and 28 deletions

View File

@@ -68,7 +68,7 @@ export default class CipherService {
decryptedCipherCache: any[];
constructor(private cryptoService: CryptoService, private userService: UserService,
private settingsService: SettingsService, private apiService: ApiService) {
private settingsService: SettingsService, private apiService: ApiService) {
}
clearCache(): void {
@@ -312,12 +312,19 @@ export default class CipherService {
const blob = new Blob([encData], { type: 'application/octet-stream' });
fd.append('data', blob, encFileName.encryptedString);
const response = await self.apiService.postCipherAttachment(cipher.id, fd);
// TODO: handle error response
let response: CipherResponse;
try {
response = await self.apiService.postCipherAttachment(cipher.id, fd);
} catch (e) {
reject((e as ErrorResponse).getSingleMessage());
return;
}
const userId = await self.userService.getUserId();
const data = new CipherData(response, userId);
this.upsert(data);
resolve(new Cipher(data));
};
reader.onerror = (evt) => {
@@ -404,13 +411,14 @@ export default class CipherService {
}
async deleteAttachmentWithServer(id: string, attachmentId: string): Promise<void> {
await this.apiService.deleteCipherAttachment(id, attachmentId);
try {
await this.apiService.deleteCipherAttachment(id, attachmentId);
} catch (e) {
return Promise.reject((e as ErrorResponse).getSingleMessage());
}
await this.deleteAttachment(id, attachmentId);
// TODO: handle error
}
// TODO: remove in favor of static refs
sortCiphersByLastUsed(a: any, b: any): number {
return CipherService.sortCiphersByLastUsed(a, b);
}
@@ -499,20 +507,4 @@ export default class CipherService {
throw new Error('Unknown cipher type.');
}
}
private handleErrorMessage(error: ErrorResponse, reject: Function): void {
if (error.validationErrors) {
for (const key in error.validationErrors) {
if (!error.validationErrors.hasOwnProperty(key)) {
continue;
}
if (error.validationErrors[key].length) {
reject(error.validationErrors[key][0]);
return;
}
}
}
reject(error.message);
return;
}
}