irby / passwordless-authenticator-poc

Avoid using promises in places not designed to handle them JS-0336
Anti-pattern
Major
a year agoa year old
Promise returned in function argument where a void return was expected
 88   * @see https://teamhanko.github.io/hanko/#/management/listUser
 89   */
 90  getCurrent(): Promise<User> {
 91    return new Promise<User>((resolve, reject) => 92      this.client 93        .get("/me") 94        .then((response) => { 95          if (response.ok) { 96            return response.json(); 97          } else if ( 98            response.status === 400 || 99            response.status === 401 ||100            response.status === 404101          ) {102            throw new UnauthorizedError();103          } else {104            throw new TechnicalError();105          }106        })107        .then((me: Me) => {108          return this.client.get(`/users/${me.id}`);109        })110        .then((response) => {111          if (response.ok) {112            return resolve(response.json());113          } else if (114            response.status === 400 ||115            response.status === 401 ||116            response.status === 404117          ) {118            throw new UnauthorizedError();119          } else {120            throw new TechnicalError();121          }122        })123        .catch((e) => {124          reject(e);125        })126    );
127  }
128}