]> Untitled Git - lemmy.git/commitdiff
Explicit error http status codes (#1362)
authorDessalines <dessalines@users.noreply.github.com>
Thu, 21 Jan 2021 16:32:19 +0000 (11:32 -0500)
committerGitHub <noreply@github.com>
Thu, 21 Jan 2021 16:32:19 +0000 (16:32 +0000)
* Trying to type specific errors.

* Using @asonix 's downcast method.

Cargo.lock
api_tests/package.json
api_tests/yarn.lock
crates/utils/Cargo.toml
crates/utils/src/lib.rs

index 02394a329bd5dfe96fca4d576ef827416250117a..70f9ec5b64697a53e861e8b50423f0e56d47a881 100644 (file)
@@ -1920,7 +1920,9 @@ dependencies = [
  "chrono",
  "comrak",
  "config",
+ "diesel",
  "futures",
+ "http",
  "itertools",
  "lazy_static",
  "lettre",
index 4ec227d58289580cc05d96cd4c8d06e64257903d..3e74a5accd06ad6083ea102679a922d206807bbc 100644 (file)
     "api-test": "jest src/ -i --verbose"
   },
   "devDependencies": {
-    "@types/jest": "^26.0.19",
+    "@types/jest": "^26.0.20",
+    "eslint": "^7.18.0",
+    "eslint-plugin-jane": "^9.0.3",
     "jest": "^26.6.3",
     "lemmy-js-client": "0.9.0-rc.12",
     "node-fetch": "^2.6.1",
-    "ts-jest": "^26.4.4",
     "prettier": "^2.1.2",
-    "eslint": "^7.10.0",
-    "eslint-plugin-jane": "^9.0.3",
+    "ts-jest": "^26.4.4",
     "typescript": "^4.1.3"
   }
 }
index 8daa3213267db22b0c76b89825c765154e17a737..8b7c8af50aa223472dc870b817ddeb0bcd087f77 100644 (file)
     exec-sh "^0.3.2"
     minimist "^1.2.0"
 
-"@eslint/eslintrc@^0.2.2":
-  version "0.2.2"
-  resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.2.2.tgz#d01fc791e2fc33e88a29d6f3dc7e93d0cd784b76"
-  integrity sha512-EfB5OHNYp1F4px/LI/FEnGylop7nOqkQ1LRzCM0KccA2U8tvV8w01KBv37LbO7nW4H+YhKyo2LcJhRwjjV17QQ==
+"@eslint/eslintrc@^0.3.0":
+  version "0.3.0"
+  resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.3.0.tgz#d736d6963d7003b6514e6324bec9c602ac340318"
+  integrity sha512-1JTKgrOKAHVivSvOYw+sJOunkBjUOvjqWk1DPja7ZFhIS2mX/4EgTT8M7eTK9jrKhL/FvXXEbQwIs3pg1xp3dg==
   dependencies:
     ajv "^6.12.4"
     debug "^4.1.1"
     ignore "^4.0.6"
     import-fresh "^3.2.1"
     js-yaml "^3.13.1"
-    lodash "^4.17.19"
+    lodash "^4.17.20"
     minimatch "^3.0.4"
     strip-json-comments "^3.1.1"
 
   dependencies:
     "@types/istanbul-lib-report" "*"
 
-"@types/jest@26.x", "@types/jest@^26.0.19":
+"@types/jest@26.x":
   version "26.0.19"
   resolved "https://registry.yarnpkg.com/@types/jest/-/jest-26.0.19.tgz#e6fa1e3def5842ec85045bd5210e9bb8289de790"
   integrity sha512-jqHoirTG61fee6v6rwbnEuKhpSKih0tuhqeFbCmMmErhtu3BYlOZaXWjffgOstMM4S/3iQD31lI5bGLTrs97yQ==
     jest-diff "^26.0.0"
     pretty-format "^26.0.0"
 
+"@types/jest@^26.0.20":
+  version "26.0.20"
+  resolved "https://registry.yarnpkg.com/@types/jest/-/jest-26.0.20.tgz#cd2f2702ecf69e86b586e1f5223a60e454056307"
+  integrity sha512-9zi2Y+5USJRxd0FsahERhBwlcvFh6D2GLQnY2FH2BzK8J9s9omvNHIbvABwIluXa0fD8XVKMLTO0aOEuUfACAA==
+  dependencies:
+    jest-diff "^26.0.0"
+    pretty-format "^26.0.0"
+
 "@types/json-schema@^7.0.3":
   version "7.0.6"
   resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0"
@@ -1825,13 +1833,13 @@ eslint-visitor-keys@^2.0.0:
   resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz#21fdc8fbcd9c795cc0321f0563702095751511a8"
   integrity sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ==
 
-eslint@^7.10.0:
-  version "7.17.0"
-  resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.17.0.tgz#4ccda5bf12572ad3bf760e6f195886f50569adb0"
-  integrity sha512-zJk08MiBgwuGoxes5sSQhOtibZ75pz0J35XTRlZOk9xMffhpA9BTbQZxoXZzOl5zMbleShbGwtw+1kGferfFwQ==
+eslint@^7.18.0:
+  version "7.18.0"
+  resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.18.0.tgz#7fdcd2f3715a41fe6295a16234bd69aed2c75e67"
+  integrity sha512-fbgTiE8BfUJZuBeq2Yi7J3RB3WGUQ9PNuNbmgi6jt9Iv8qrkxfy19Ds3OpL1Pm7zg3BtTVhvcUZbIRQ0wmSjAQ==
   dependencies:
     "@babel/code-frame" "^7.0.0"
-    "@eslint/eslintrc" "^0.2.2"
+    "@eslint/eslintrc" "^0.3.0"
     ajv "^6.10.0"
     chalk "^4.0.0"
     cross-spawn "^7.0.2"
@@ -1855,7 +1863,7 @@ eslint@^7.10.0:
     js-yaml "^3.13.1"
     json-stable-stringify-without-jsonify "^1.0.1"
     levn "^0.4.1"
-    lodash "^4.17.19"
+    lodash "^4.17.20"
     minimatch "^3.0.4"
     natural-compare "^1.4.0"
     optionator "^0.9.1"
index df4ae1b2bc4818573aa8f36bcc8326971e53f0f7..052ceb206e6c693caa6d5493a9617a3f83617631 100644 (file)
@@ -31,3 +31,5 @@ tokio = { version = "0.3.6", features = ["sync"] }
 strum = "0.20.0"
 strum_macros = "0.20.1"
 futures = "0.3.8"
+diesel = "1.4.5"
+http = "0.2.2"
index e0b8e3aa1dcc6186c749ac2e973266ebaafa43d7..2cc29131fe7774648bb2a6111851dedba373a3ce 100644 (file)
@@ -13,6 +13,7 @@ mod test;
 pub mod utils;
 
 use crate::settings::Settings;
+use http::StatusCode;
 use regex::Regex;
 use thiserror::Error;
 
@@ -68,7 +69,14 @@ impl std::fmt::Display for LemmyError {
   }
 }
 
-impl actix_web::error::ResponseError for LemmyError {}
+impl actix_web::error::ResponseError for LemmyError {
+  fn status_code(&self) -> StatusCode {
+    match self.inner.downcast_ref::<diesel::result::Error>() {
+      Some(diesel::result::Error::NotFound) => StatusCode::NOT_FOUND,
+      _ => StatusCode::INTERNAL_SERVER_ERROR,
+    }
+  }
+}
 
 lazy_static! {
   pub static ref WEBFINGER_COMMUNITY_REGEX: Regex = Regex::new(&format!(