各レイヤーからのエラーについて考える

 各レイヤーからのエラーについて考える

関西Javaエンジニアの会(関ジャバ) '17 10月度
https://kanjava.connpass.com/event/68169/

C952d9f90c7ec6cb1b5513c05d3db536?s=128

yoshiyoshifujii

October 21, 2017
Tweet

Transcript

  1. ֤ϨΠϠʔ͔Βͷ Τϥʔʹ͍ͭͯߟ͑Δ  4BU !ZPTIJZPTIJGVKJJ

  2. ͜Μʹͪ͸ w:PTIJUBLB'VKJJ !ZPTIJZPTIJGVKJJ w4PGUXBSF&OHJOFFS w4DBMB+BWB1ZUIPO 5ZQFTDSJQU w4DBMBؔ੢4VNNJU4UB⒎

  3. ձ৔εϙϯαʔ΍ͬͯ·͢

  4. ି͠ग़͠Ͱ͖Δ෦԰ w ηϛφʔϗʔϧ ໊  w ձٞࣨ ໊͔Β໊  w

    ΧϑΣεϖʔε ໊  w ϏΞόογϡͳͲͷ࠙਌ձ΋։࠵ՄೳͰ͢ʂ
  5. ࠓ೔ͷ͓࿩ͷલఏ w3&45"1*ͷαʔόαΠυ
 ը໘͸ؚΈ·ͤΜ  w4DBMB w࣮ફͯ͠Έͨ݁ՌΛ੔ཧ w.BZFSຊ͸ಡΜͰ·ͤΜ

  6. Τϥʔͷ෼ྨ wϢʔβʔͷૢ࡞ΛىҼͱ͢ΔΤϥʔ wγεςϜͷো֐ΛىҼͱ͢ΔΤϥʔ

  7. Ϣʔβʔͷૢ࡞ΛىҼͱ͢Δ wܖ໿ʹҧ൓͢ΔΑ͏ͳૢ࡞ wඞਢɺ௕͞ɺܕɺॏෳͳͲ wجຊతʹ͸ը໘ଆͰ֬ೝ͢Δ wࠓճ͸ɺ"1*Λ௚઀ݺͼग़͢͜ͱΛ૝ఆ wෆਖ਼ΞΫηε

  8. γεςϜͷো֐ΛىҼͱ͢Δ w*0ྫ֎ w/FUXPSLɺ4ZTUFN%PXO wόά w͵ΔΆ

  9. )551εςʔλείʔυ wϢʔβʔͷૢ࡞൪୆ wγεςϜͷো֐൪୆

  10. υϝΠϯۦಈઃܭ

  11. -BZFSFE"SDIJUFDUVSF w6TFS*OUFSGBDF w"QQMJDBUJPO w%PNBJO w*OGSBTUSVDUVSF &WBOT &SJD%PNBJO%SJWFO%FTJHO5BDLMJOH$PNQMFYJUZJOUIF)FBSUPG4PGUXBSF ,JOEMFͷҐஔ/P 1FBSTPO&EVDBUJPO,JOEMF൛

  12. ࡾ૚ υϝΠϯϞσϧ wϓϨθϯςʔγϣϯ૚ wΞϓϦέʔγϣϯ૚ wσʔλιʔε૚ wυϝΠϯϞσϧ ૿ాږݱ৔Ͱ໾ཱͭγεςϜઃܭͷݪଇʙมߋΛָͰ҆શʹ͢ΔΦϒδΣΫτࢦ޲ͷ࣮ફٕ๏ ,JOEMFͷҐஔ/P גࣜձٕࣾज़ධ࿦ࣾ,JOEMF൛

  13. ΦχΦϯΞʔΩςΫνϟ wΠϯλʔϑΣʔε wΞϓϦέʔγϣϯ wυϝΠϯ wΠϯϑϥετϥΫνϟ IUUQTTQFBLFSEFDLDPNDSPTTSPBETDBMBPOEEE TMJEF

  14. ΠϯϑϥετϥΫνϟ Πϯϑϥ αʔϏε υϝΠϯ ϨΠϠʔͰѻ͏Τϥʔ ΠϯλʔϑΣʔε ΞϓϦέʔγϣϯ ϑΝΫτϦ ΤϯςΟςΟ υϝΠϯ

    αʔϏε ϦϙδτϦ ΠϕϯτύϒϦ ογϟ ϦϙδτϦ࣮૷ Πϕϯτ ύϒϦογϟ࣮૷ +BWBϥΠϒϥϦ +%#$υϥΠό౳ ྫ֎ ϦϙδτϦ Τϥʔ ΞϓϦέʔγ ϣϯΤϥʔ υϝΠϯ Τϥʔ ࢀߟIUUQTTQFBLFSEFDLDPNDSPTTSPBETDBMBPOEEE TMJEF 5SZ\ʜ^Ͱғͬͯྫ֎Λ 5SZܕʹม׵ 5SZ
  15. υϝΠϯ૚

  16. υϝΠϯ૚ͷΤϥʔ wܖ໿ҧ൓ wඞਢ wܕνΣοΫ w௕͞ɺ୹͔͞ wॏෳ w%PNBJO&SSPSܕ

  17. ϦϙδτϦ͸υϝΠϯͱಉ͡ wυϝΠϯ૚ʹϦϙδτϦΛఆٛ͢Δ wυϝΠϯͷΤϥʔܕͱಉ͡ʹ͢Δ͔

  18. ϦϙδτϦͷ੹຿Λߟ͑Δ wυϝΠϯͷӬଓԽ w࠶ੜ੒ w*0ྫ֎ΛΑ͘ѻ͍ͦ͏

  19. ϦϙδτϦͰҙ֎ͱߟྀ͢΂͖͜ͱ wָ؍ഉଞ 0QUJNJTUJD-PDLJOH  w/PU'PVOE 0QUJPOPS'BJMVSF  w͜ΕΒΛܕͰද໌ͨ͘͠ͳΔ

  20. ϑΝΫτϦ͸υϝΠϯͱಉ͡ wϑΝΫτϦ͸υϝΠϯΛੜ੒͢Δ wυϝΠϯͷੜ੒࣌ʹܖ໿ҧ൓Λ֬ೝ͢ Δ wυϝΠϯͷΤϥʔͱಉ͡Ͱྑ͍

  21. ΠϕϯτύϒϦογϟ͸ wυϝΠϯΠϕϯτͷύϒϦογϡ wܖ໿ҧ൓ͷݕূ͸ऴΘͬͨঢ়ଶ w*0ྫ֎ͷΈΛߟྀͰྑ͍

  22. υϝΠϯαʔϏε͸ wυϝΠϯͷϏδωεϧʔϧΛѻ͏ wܖ໿ҧ൓Λѻ͏ wϦϙδτϦ͸ѻΘͳ͍

  23. υϝΠϯ૚ͷΤϥʔܕ w%PNBJO&SSPSܕ w3FQPTJUPSZ&SSPSܕ wྫ֎ TDBMBVUJM5SZ

  24. Πϯϑϥ ετϥΫνϟ૚

  25. ΠϯϑϥετϥΫνϟ Πϯϑϥ αʔϏε υϝΠϯ ϨΠϠʔͰѻ͏Τϥʔ ΠϯλʔϑΣʔε ΞϓϦέʔγϣϯ ϑΝΫτϦ ΤϯςΟςΟ υϝΠϯ

    αʔϏε ϦϙδτϦ ΠϕϯτύϒϦ ογϟ ϦϙδτϦ࣮૷ Πϕϯτ ύϒϦογϟ࣮૷ +BWBϥΠϒϥϦ +%#$υϥΠό౳ ྫ֎ ϦϙδτϦ Τϥʔ ΞϓϦέʔγ ϣϯΤϥʔ υϝΠϯ Τϥʔ ࢀߟIUUQTTQFBLFSEFDLDPNDSPTTSPBETDBMBPOEEE TMJEF 5SZ\ʜ^Ͱғͬͯྫ֎Λ 5SZܕʹม׵ 5SZ
  26. ϦϙδτϦ࣮૷ wυϝΠϯ૚ͷఆٛʹै͏ w3%#ɺ,74ɺ"84 ,JOFTJTɺ424ɺ4  w+BWB-JCSBSZ wྫ֎ΛUSZDBUDIͯ͠$POWFSU w-JCSBSZͷґଘܕ͸ด͡ࠐΊΔ

  27. ΠϕϯτύϒϦογϟ࣮૷ wྫ֎Λͦͷ··ѻ͏ wಛผʹܕΛఆٛͯ͠ѻΘͳ͍

  28. ΠϯϑϥετϥΫνϟαʔϏε wυϝΠϯͰදݱ͢Δඞཁͷͳ͍Πϯϑϥ ૢ࡞ wϑΝΠϧΞοϓϩʔυΛςϯϙϥϦʔʹ Ұ࣌อଘ w҉߸Խ෮߸

  29. ΠϯϑϥετϥΫνϟ૚ͷΤϥʔܕ w3FQPTJUPSZ&SSPSܕ wྫ֎

  30. ΞϓϦέʔγϣϯ ૚

  31. ΠϯϑϥετϥΫνϟ Πϯϑϥ αʔϏε υϝΠϯ ϨΠϠʔͰѻ͏Τϥʔ ΠϯλʔϑΣʔε ΞϓϦέʔγϣϯ ϑΝΫτϦ ΤϯςΟςΟ υϝΠϯ

    αʔϏε ϦϙδτϦ ΠϕϯτύϒϦ ογϟ ϦϙδτϦ࣮૷ Πϕϯτ ύϒϦογϟ࣮૷ +BWBϥΠϒϥϦ +%#$υϥΠό౳ ྫ֎ ϦϙδτϦ Τϥʔ ΞϓϦέʔγ ϣϯΤϥʔ υϝΠϯ Τϥʔ ࢀߟIUUQTTQFBLFSEFDLDPNDSPTTSPBETDBMBPOEEE TMJEF 5SZ\ʜ^Ͱғͬͯྫ֎Λ 5SZܕʹม׵ 5SZ
  32. ΞϓϦέʔγϣϯαʔϏε wϢʔεέʔεهड़Λॻ͘Α͏ʹ wϢʔεέʔεͱͯ͠ΤϥʔΛද໌͢Δ w%PNBJO&SSPS 3FQPTJUPSZ&SSPS ྫ֎ Λ$POWFSU

  33. ΞϓϦέʔγϣϯΤϥʔ wϢʔεέʔεͱͯ͠ͷ Τϥʔද໌ w/PU'PVOE w#BE3FRVFTU w4ZTUFN&SSPS

  34. $POWFSUΛ੔ཧ w%PNBJO&SSPS"QQMJDBUJPO&SSPS w3FQPTJUPSZ&SSPS"QQMJDBUJPO&SSPS wྫ֎"QQMJDBUJPO&SSPS

  35. $POWFSUΛ੔ཧ wΤϥʔܕΛද໌ͨ͜͠ͱͰ$POWFSU͕ େม wશͯ"QQMJDBUJPO&SSPSʹ͢Δ w$POWFSUΛ͏·࣮͘૷͠ͳ͍ͱਏ͍

  36. object ApplicationErrorConverters { implicit class DomainError2ApplicationError[E](val e: Either[DomainError, E]) extends

    AnyVal { def toApplicationError: Either[ApplicationError, E] = e.fold( l => Left(BadRequestError(Option(l.message))), Right(_) ) } }
  37. object ApplicationErrorConverters { implicit class RepositoryError2ApplicationError[E](val e: Either[RepositoryError, E]) extends

    AnyVal { def toApplicationError: Either[ApplicationError, E] = e.fold( { case _: RepositoryOptimisticError => Left(ConflictError) case _: RepositoryNotFoundError => Left(NoContentsError) case _: RepositoryAlreadyExistsError => Left(BadRequestError(Some("already_exists"))) case RepositorySystemError(t) => Left(InternalServerError(t)) }, Right(_) ) } }
  38. object ApplicationErrorConverters { implicit class Try2ApplicationError[E](val e: Try[E]) extends AnyVal

    { def toApplicationError: Either[ApplicationError, E] = e.fold( e => Left(InternalServerError(e)), Right(_) ) } }
  39. ΠϯλʔϑΣʔε ૚

  40. ΠϯϑϥετϥΫνϟ Πϯϑϥ αʔϏε υϝΠϯ ϨΠϠʔͰѻ͏Τϥʔ ΠϯλʔϑΣʔε ΞϓϦέʔγϣϯ ϑΝΫτϦ ΤϯςΟςΟ υϝΠϯ

    αʔϏε ϦϙδτϦ ΠϕϯτύϒϦ ογϟ ϦϙδτϦ࣮૷ Πϕϯτ ύϒϦογϟ࣮૷ +BWBϥΠϒϥϦ +%#$υϥΠό౳ ྫ֎ ϦϙδτϦ Τϥʔ ΞϓϦέʔγ ϣϯΤϥʔ υϝΠϯ Τϥʔ ࢀߟIUUQTTQFBLFSEFDLDPNDSPTTSPBETDBMBPOEEE TMJEF 5SZ\ʜ^Ͱғͬͯྫ֎Λ 5SZܕʹม׵ 5SZ
  41. "QQMJDBUJPO&SSPSΛ$POWFSU w)551εςʔλεʹม׵ w/PU'PVOE w#BE3FRVFTU w*OUFSOBM4FSWFS&SSPS

  42. )551Ҏ֎ͷΠϯλϑΣʔε w4VCTDSJCFS w3FDJFWFS w$PNNBOE-JOF*OUFSGBDF

  43. 4VCTDSJCFS w/PU'PVOE4LJQ w#BE3FRVFTU4LJQ w*OUFSOBM4FSWFS&SSPS3FUSZ

  44. ΠϯλϑΣʔεʹґଘ͢Δ wΠϯλϑΣʔε͕)551ͳΒ)551ʹ w4VC3FDJFWFSͳΒ4LJQ͔3FUSZ wӬԕʹղফ͞Εͳ͍3FUSZΛ࡞ͬͯॲ ཧΛ஗Ԇͤ͞ͳ͍Α͏൑அ͕ཁΔ

  45. 'JO