mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-22 19:53:48 +08:00
fix: error handle in payment resolver (#4754)
This commit is contained in:
@@ -1,8 +1,4 @@
|
|||||||
import {
|
import { HttpStatus } from '@nestjs/common';
|
||||||
BadGatewayException,
|
|
||||||
ForbiddenException,
|
|
||||||
InternalServerErrorException,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import {
|
import {
|
||||||
Args,
|
Args,
|
||||||
Field,
|
Field,
|
||||||
@@ -16,6 +12,7 @@ import {
|
|||||||
Resolver,
|
Resolver,
|
||||||
} from '@nestjs/graphql';
|
} from '@nestjs/graphql';
|
||||||
import type { User, UserInvoice, UserSubscription } from '@prisma/client';
|
import type { User, UserInvoice, UserSubscription } from '@prisma/client';
|
||||||
|
import { GraphQLError } from 'graphql';
|
||||||
import { groupBy } from 'lodash-es';
|
import { groupBy } from 'lodash-es';
|
||||||
|
|
||||||
import { Config } from '../../config';
|
import { Config } from '../../config';
|
||||||
@@ -168,9 +165,12 @@ export class SubscriptionResolver {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!yearly || !monthly) {
|
if (!yearly || !monthly) {
|
||||||
throw new BadGatewayException(
|
throw new GraphQLError('The prices are not configured correctly', {
|
||||||
'The prices are not configured correctly'
|
extensions: {
|
||||||
);
|
status: HttpStatus[HttpStatus.BAD_GATEWAY],
|
||||||
|
code: HttpStatus.BAD_GATEWAY,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -198,9 +198,12 @@ export class SubscriptionResolver {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!session.url) {
|
if (!session.url) {
|
||||||
throw new InternalServerErrorException(
|
throw new GraphQLError('Failed to create checkout session', {
|
||||||
'Failed to create checkout session'
|
extensions: {
|
||||||
);
|
status: HttpStatus[HttpStatus.BAD_GATEWAY],
|
||||||
|
code: HttpStatus.BAD_GATEWAY,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return session.url;
|
return session.url;
|
||||||
@@ -240,7 +243,15 @@ export class UserSubscriptionResolver {
|
|||||||
@ResolveField(() => UserSubscriptionType, { nullable: true })
|
@ResolveField(() => UserSubscriptionType, { nullable: true })
|
||||||
async subscription(@CurrentUser() me: User, @Parent() user: User) {
|
async subscription(@CurrentUser() me: User, @Parent() user: User) {
|
||||||
if (me.id !== user.id) {
|
if (me.id !== user.id) {
|
||||||
throw new ForbiddenException();
|
throw new GraphQLError(
|
||||||
|
'You are not allowed to access this subscription',
|
||||||
|
{
|
||||||
|
extensions: {
|
||||||
|
status: HttpStatus[HttpStatus.FORBIDDEN],
|
||||||
|
code: HttpStatus.FORBIDDEN,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.db.userSubscription.findUnique({
|
return this.db.userSubscription.findUnique({
|
||||||
@@ -259,7 +270,12 @@ export class UserSubscriptionResolver {
|
|||||||
@Args('skip', { type: () => Int, nullable: true }) skip?: number
|
@Args('skip', { type: () => Int, nullable: true }) skip?: number
|
||||||
) {
|
) {
|
||||||
if (me.id !== user.id) {
|
if (me.id !== user.id) {
|
||||||
throw new ForbiddenException();
|
throw new GraphQLError('You are not allowed to access this invoices', {
|
||||||
|
extensions: {
|
||||||
|
status: HttpStatus[HttpStatus.FORBIDDEN],
|
||||||
|
code: HttpStatus.FORBIDDEN,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.db.userInvoice.findMany({
|
return this.db.userInvoice.findMany({
|
||||||
|
|||||||
Reference in New Issue
Block a user