summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-04-19 18:58:57 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-04-19 18:58:57 +0900
commit5d0ded2a693e7370321c0494d825c55ee066997b (patch)
treeb6ded4a5be742184b822117fce3a64d0a2e8ddde /src
parentImplement suspend account (diff)
downloadmisskey-5d0ded2a693e7370321c0494d825c55ee066997b.tar.gz
misskey-5d0ded2a693e7370321c0494d825c55ee066997b.tar.bz2
misskey-5d0ded2a693e7370321c0494d825c55ee066997b.zip
Better error handling
Diffstat (limited to 'src')
-rw-r--r--src/remote/activitypub/models/person.ts53
1 files changed, 32 insertions, 21 deletions
diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts
index dd9a80ae23..be035097b9 100644
--- a/src/remote/activitypub/models/person.ts
+++ b/src/remote/activitypub/models/person.ts
@@ -80,27 +80,38 @@ export async function createPerson(value: any, resolver?: Resolver): Promise<IUs
const summaryDOM = JSDOM.fragment(person.summary);
// Create user
- const user = await User.insert({
- avatarId: null,
- bannerId: null,
- createdAt: Date.parse(person.published) || null,
- description: summaryDOM.textContent,
- followersCount,
- followingCount,
- notesCount,
- name: person.name,
- driveCapacity: 1024 * 1024 * 8, // 8MiB
- username: person.preferredUsername,
- usernameLower: person.preferredUsername.toLowerCase(),
- host,
- publicKey: {
- id: person.publicKey.id,
- publicKeyPem: person.publicKey.publicKeyPem
- },
- inbox: person.inbox,
- uri: person.id,
- url: person.url
- }) as IRemoteUser;
+ let user: IRemoteUser;
+ try {
+ user = await User.insert({
+ avatarId: null,
+ bannerId: null,
+ createdAt: Date.parse(person.published) || null,
+ description: summaryDOM.textContent,
+ followersCount,
+ followingCount,
+ notesCount,
+ name: person.name,
+ driveCapacity: 1024 * 1024 * 8, // 8MiB
+ username: person.preferredUsername,
+ usernameLower: person.preferredUsername.toLowerCase(),
+ host,
+ publicKey: {
+ id: person.publicKey.id,
+ publicKeyPem: person.publicKey.publicKeyPem
+ },
+ inbox: person.inbox,
+ uri: person.id,
+ url: person.url
+ }) as IRemoteUser;
+ } catch (e) {
+ // duplicate key error
+ if (e.code === 11000) {
+ throw new Error('already registered');
+ }
+
+ console.error(e);
+ throw e;
+ }
//#region アイコンとヘッダー画像をフェッチ
const [avatarId, bannerId] = (await Promise.all([