Upgrade to Pro — share decks privately, control downloads, hide ads and more …

BAD_REQUEST = 400 をめぐる問い。マジックナンバーは可読性を下げるのか? / bad request is 400

qsona
August 03, 2019

BAD_REQUEST = 400 をめぐる問い。マジックナンバーは可読性を下げるのか? / bad request is 400

すえなみチャンス暑気払い

qsona

August 03, 2019
Tweet

More Decks by qsona

Other Decks in Technology

Transcript

  1. BAD_REQUEST = 400 ΛΊ͙Δ໰͍ɻ
    ϚδοΫφϯόʔ͸ՄಡੑΛ

    Լ͛Δͷ͔?
    @qsona (FiNC Technologies)

    View full-size slide

  2. ࠓ೔࿩͢͜ͱ
    • BAD_REQUEST = 400 ͷྫ͔Β

    ϚδοΫφϯόʔͷੋඇͳͲʹ๲Β·ͤͯٞ࿦͢Δ
    • ͦͷաఔͰɺʮઃܭͷݴޠԽʯͷॏཁ͞Λ

    ͋ΒͨΊͯڧௐ͍ͨ͠

    View full-size slide

  3. ࠓ೔ͷείʔϓ֎
    • ͦ΋ͦ΋εςʔλείʔυ

    Λ࢖͍෼͚Δ΂͖͔
    • ྫ: validation error ͷͱ͖ʹ

    400 BAD REQUEST

    Λฦ͢΂͖͔Ͳ͏͔
    • ͜Ε͸͜ΕͰਂ͍࿩

    View full-size slide

  4. ૝૾ͯͨ͠΍ͭ

    View full-size slide

  5. ͳΜͱͳ͍͘΍ͳίʔυ

    View full-size slide

  6. ࡶͳࢦఠ
    • BAD REQUEST ͕ 400ͱ͔

    ͩΕͰ΋஌ͬͯΔΑͶ?
    • ࡶͳݴޠԽ

    View full-size slide

  7. ॏཁͳࢦఠ

    View full-size slide

  8. ΫΠζ
    • HTTPεςʔλείʔυ 409

    View full-size slide

  9. ΫΠζ
    • HTTPεςʔλείʔυ 409 ͸ҎԼͷ͏ͪͲΕ
    • PERMANENT REDIRECT
    • INSUFFICIENT STORAGE
    • CONFLICT
    • PROCESSING

    View full-size slide

  10. ΫΠζ
    • HTTPεςʔλείʔυ 409 ͸ҎԼͷ͏ͪͲΕ
    • 308 PERMANENT REDIRECT
    • 507 INSUFFICIENT STORAGE
    • 409 CONFLICT
    • 102 PROCESSING

    View full-size slide

  11. ࿦఺
    • ϚδοΫφϯόʔͷੋඇ
    • HTTPεςʔλείʔυΛ਺஋Ͱϕλॻ͖͢Δ͜ͱͷੋඇ

    View full-size slide

  12. ϚδοΫφϯόʔΛΊ͙Δ࿦఺
    • "Մಡੑ͕ѱ͍" (not readable)
    • ࡶͳݴޠԽ

    View full-size slide

  13. ϚδοΫφϯόʔͷՄಡੑ͕௿͍ͱ͸
    • Կʹର͢Δ਺஋͔͕ͩΘ͔Βͳ͍Α
    • ਺஋ࣗମͷࠜڌ(ଥ౰ੑ)͕Θ͔Βͳ͍Α
    • ڞ௨Խ͞Εͯͳ͍Α
    • ϚδοΫφϯόʔ͸ѱɺ໰౴ແ༻

    View full-size slide

  14. Կʹର͢Δ਺஋͔͕ͩΘ͔Βͳ͍Α
    • price * 1.08
    • ͦ΋ͦ΋ 1.08 ͕͜͜ʹग़͖͍ͯͯΔཧ༝͕Θ͔Βͳ͍
    • ਺஋ԋࢉͯ͠Δͱ͖ʹى͖͕ͪ

    View full-size slide

  15. Կʹର͢Δ਺஋͔͕ͩΘ͔Βͳ͍Α
    • ؔ਺(ϝιου)ݺͼग़͠ʹ਺஋Λ౉͢ͱ͖͸ɺ

    ͜ͷ໰୊͸ى͜Βͳ͍
    • ϝιουఆٛΛݟΕ͹Θ͔ΔͷͰ
    • લͷྫͰ͸ TAX_RATE ఆ਺Λఆٛ͢ΔΑΓ΋ɺ(ྫ͑͹)

    price_included_tax(base_price) ϝιουΛఆٛͨ͠΄͏͕͍͍

    View full-size slide

  16. ਺஋ࣗମͷࠜڌ(ଥ౰ੑ)͕Θ͔Βͳ͍Α
    • 409 ͕εςʔλείʔυΛදͯ͠Δͷ͸Θ͔Δ͕ɺ

    ͳͥ 409 ͳͷ͔͕Θ͔Βͳ͍
    • ׂͱϚΠφʔͳ໰୊ͳؾ͕ͯ͠Δɻ͜Εʹ͍ͭͯ͸ޙड़

    View full-size slide

  17. ڞ௨Խ͞Εͯͳ͍Α
    • ڞ௨Խ͢΂͖ͳΒͯ͘͠Ε
    • Ͳ͏͍͏࣌ʹڞ௨Խ͢΂͖͔͸Θ͔Δͳ?

    View full-size slide

  18. const LIMIT = 10; ໰୊

    View full-size slide

  19. const LIMIT = 10; ໰୊
    • Լͷ͏ͪ1ͭ΋ղܾ͍ͯ͠ͳ͍
    • Կʹର͢Δ਺஋͔͕ͩ

    Θ͔Βͳ͍Α
    • ਺஋ࣗମͷࠜڌ(ଥ౰ੑ)͕

    Θ͔Βͳ͍Α
    • ڞ௨Խ͞Εͯͳ͍Α

    View full-size slide

  20. ๻ͷதͰͷਖ਼ղ

    View full-size slide

  21. ֮͑Δඞཁ͸ͳ͍
    • 409 => conflict ͸άάΕ͹ҰॠͰग़ͯ͘Δ
    • ඞཁʹͳΔස౓ͷ໰୊
    • ස౓͕ଟ͍ͳΒ͔֬ʹ໰୊͚ͩͲɺ

    ͦΜͳʹ͠ΐͬͪΎ͏͋Δ...?

    View full-size slide

  22. ͲͪΒͷ৘ใྔ͕େࣄ͔?
    • 409
    • ࢓༷ɺΠϯλʔϑΣΠε
    • conflict
    • ҙຯɺ࣮૷ʹ͍ۙ

    View full-size slide

  23. ΠϯλʔϑΣΠεͷॏཁੑ
    • ྫ͑͹ OpenAPI 3
    • Web API ͷ࢓༷ͷ

    υΩϡϝϯτ
    • ͜͜ʹ͸ `409` ͱ਺஋Ͱ
    ॻ͘

    View full-size slide

  24. 4xx = Client Error
    • 409 ͩͬͨΒͱΓ͋͑ͣ Client Errorͩͱ͍͏ͱ͜Ζ·Ͱ͸

    Θ͔Δ
    • Conflict ͬͯݴΘΕͯ΋Α͘Θ͔Βͳ͘ͳ͍...?

    View full-size slide

  25. ·ͱΊ
    • ؒҧ͍ͳ͘࢒೦ͳίʔυ͸ݴ͍ա͗ͩͬͨɺ͢·Μ
    • ϚδοΫφϯόʔ͸࠷ߴ
    • ઃܭ͸ݴޠԽΛ͍ͯ͜͠͏
    • ͑͢ͳΈνϟϯε͸ࣗΒͷखͰ௫Ή΋ͷ

    View full-size slide