feat: console error

This commit is contained in:
Nevo David 2024-09-25 11:56:25 +07:00
parent b4beee65da
commit c84d8af915
2 changed files with 16 additions and 23 deletions

View File

@ -290,17 +290,6 @@ export class PostsService {
return this.postSocial(integration, posts, true);
}
if (
err instanceof BadBody &&
process.env.EMAIL_FROM_ADDRESS === 'nevo@postiz.com'
) {
await this._notificationService.sendEmail(
'nevo@positz.com',
'Bad body',
JSON.stringify(err.body)
);
}
throw err;
}
}

View File

@ -1,7 +1,8 @@
export class RefreshToken {}
export class RefreshToken {
constructor(public json: string, public body: BodyInit) {}
}
export class BadBody {
constructor(public body: BodyInit) {
}
constructor(public json: string, public body: BodyInit) {}
}
export class NotEnoughScopes {}
@ -10,20 +11,23 @@ export abstract class SocialAbstract {
async fetch(url: string, options: RequestInit = {}) {
const request = await fetch(url, options);
if (request.status !== 200 && request.status !== 201) {
try {
console.log(await request.json());
}
catch (err) {
console.log('skip');
}
if (request.status === 200 || request.status === 201) {
return request;
}
let json = '{}';
try {
json = await request.json();
} catch (err) {
json = '{}';
}
if (request.status === 401) {
throw new RefreshToken();
throw new RefreshToken(json, options.body!);
}
if (request.status === 400) {
throw new BadBody(options.body!);
throw new BadBody(json, options.body!);
}
return request;