error-utils.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. export default {
  19. getErrorTypeByErrorCode: function(code) {
  20. var errorType = '';
  21. if (code) {
  22. switch (code) {
  23. case "500":
  24. errorType = "Internal Server Error";
  25. break;
  26. case "502":
  27. errorType = "Bad Gateway";
  28. break;
  29. case "503":
  30. errorType = "Service Unavailable";
  31. break;
  32. case "400":
  33. errorType = "Bad Request";
  34. break;
  35. case "403":
  36. errorType = "Forbidden";
  37. break;
  38. case "404":
  39. errorType = "Not Found";
  40. break;
  41. default:
  42. errorType = "";
  43. break;
  44. }
  45. }
  46. return errorType;
  47. },
  48. stripErrorCodeAndMessageFromError: function(err) {
  49. var obj = {};
  50. if (err && err.errors && err.errors[0]) {
  51. obj.errorCode = err.errors[0].status || "";
  52. obj.title = err.errors[0].title || "";
  53. obj.errorType = this.getErrorTypeByErrorCode(err.errors[0].status);
  54. }
  55. return obj;
  56. }
  57. };