1212use OCP \AppFramework \Http ;
1313use OCP \AppFramework \Http \Attribute \NoAdminRequired ;
1414use OCP \AppFramework \Http \DataResponse ;
15+ use OCP \AppFramework \OCS \OCSBadRequestException ;
1516use OCP \AppFramework \OCSController ;
1617use OCP \IConfig ;
1718use OCP \IRequest ;
@@ -30,53 +31,52 @@ public function __construct(
3031 parent ::__construct ($ appName , $ request );
3132 }
3233
34+ /**
35+ * @throws OCSBadRequestException
36+ */
3337 private function validateGetUserSetting (string $ setting ): void {
3438 if ($ setting === 'user_folder ' ) {
3539 return ;
3640 }
3741
38- throw new InvalidArgumentException ('Unsupported setting ' . $ setting );
42+ throw new OCSBadRequestException ('Unsupported setting ' . $ setting );
3943 }
4044
4145 /**
42- * @throws InvalidArgumentException
46+ * @throws OCSBadRequestException
4347 */
4448 private function validateSetUserSetting (string $ setting , ?string $ value ): void {
4549 if ($ value === null ) {
46- throw new InvalidArgumentException ('Empty value for setting ' . $ setting );
50+ throw new OCSBadRequestException ('Empty value for setting ' . $ setting );
4751 }
4852
4953 if ($ setting === 'user_folder ' ) {
5054 // No root folder, has to start with `/`, not allowed to end with `/`
5155 if ($ value === '/ '
5256 || !(str_starts_with ($ value , '/ ' ))
5357 || str_ends_with ($ value , '/ ' )) {
54- throw new InvalidArgumentException ('Invalid collectives folder path ' );
58+ throw new OCSBadRequestException ('Invalid collectives folder path ' );
5559 }
5660
5761 return ;
5862 }
5963
60- throw new InvalidArgumentException ('Unsupported setting ' . $ setting );
64+ throw new OCSBadRequestException ('Unsupported setting ' . $ setting );
6165 }
6266
6367 /**
6468 * Get a collectives user setting by key (defaults to empty string if key is unset)
6569 *
6670 * @param string $key The key to get
6771 *
68- * @return DataResponse<Http::STATUS_OK, array<string>, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: string}, array{}>
72+ * @return DataResponse<Http::STATUS_OK, array<string>, array{}>
73+ * @throws OCSBadRequestException Invalid key
6974 *
7075 * 200: Valid key, value returned
71- * 400: Invalid key
7276 */
7377 #[NoAdminRequired]
7478 public function getUserSetting (string $ key ): DataResponse {
75- try {
76- $ this ->validateGetUserSetting ($ key );
77- } catch (InvalidArgumentException $ e ) {
78- return new DataResponse (['error ' => $ e ->getMessage ()], Http::STATUS_BAD_REQUEST );
79- }
79+ $ this ->validateGetUserSetting ($ key );
8080 return new DataResponse ([$ key => $ this ->config ->getUserValue ($ this ->userId , 'collectives ' , $ key , '' )]);
8181 }
8282
@@ -86,18 +86,14 @@ public function getUserSetting(string $key): DataResponse {
8686 * @param string $key The key to set
8787 * @param string $value The value
8888 *
89- * @return DataResponse<Http::STATUS_OK, array<string>, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: string}, array{}>
89+ * @return DataResponse<Http::STATUS_OK, array<string>, array{}>
90+ * @throws OCSBadRequestException Invalid key
9091 *
9192 * 200: Valid key set to value
92- * 400: Invalid key
9393 */
9494 #[NoAdminRequired]
9595 public function setUserSetting (string $ key , string $ value ): DataResponse {
96- try {
97- $ this ->validateSetUserSetting ($ key , $ value );
98- } catch (InvalidArgumentException $ e ) {
99- return new DataResponse (['error ' => $ e ->getMessage ()], Http::STATUS_BAD_REQUEST );
100- }
96+ $ this ->validateSetUserSetting ($ key , $ value );
10197 $ this ->config ->setUserValue ($ this ->userId , 'collectives ' , $ key , $ value );
10298 return new DataResponse ([$ key => $ value ]);
10399 }
0 commit comments