It("returns a UAADownError", func() { uaaClient.UsersEmailsByIDsCall.Returns.Error = uaa.NewFailure(404, []byte("Requested route ('uaa.10.244.0.34.xip.io') does not exist")) _, err := loader.Load([]string{"user-123"}, token) Expect(err).To(BeAssignableToTypeOf(postal.UAADownError(""))) }) }) Context("when UAA returns an unknown UAA 404 error", func() { It("returns a UAAGenericError", func() { uaaClient.UsersEmailsByIDsCall.Returns.Error = uaa.NewFailure(404, []byte("Weird message we haven't seen")) _, err := loader.Load([]string{"user-123"}, token) Expect(err).To(BeAssignableToTypeOf(postal.UAAGenericError(""))) }) }) Context("when UAA returns an failure code that is not 404", func() { It("returns a UAADownError", func() { uaaClient.UsersEmailsByIDsCall.Returns.Error = uaa.NewFailure(500, []byte("Doesn't matter")) _, err := loader.Load([]string{"user-123"}, token) Expect(err).To(BeAssignableToTypeOf(postal.UAADownError(""))) }) }) }) }) })
It("returns a 502 when UAA fails to respond", func() { writer.Write(recorder, postal.UAADownError("Whoops!")) Expect(recorder.Code).To(Equal(http.StatusBadGateway)) body := make(map[string]interface{}) err := json.Unmarshal(recorder.Body.Bytes(), &body) if err != nil { panic(err) } Expect(body["errors"]).To(ContainElement("Whoops!")) }) It("returns a 502 when UAA fails for unknown reasons", func() { writer.Write(recorder, postal.UAAGenericError("UAA Unknown Error: BOOM!")) Expect(recorder.Code).To(Equal(http.StatusBadGateway)) body := make(map[string]interface{}) err := json.Unmarshal(recorder.Body.Bytes(), &body) if err != nil { panic(err) } Expect(body["errors"]).To(ContainElement("UAA Unknown Error: BOOM!")) }) It("returns a 500 and writes the error message when there is a template loading error", func() { writer.Write(recorder, postal.TemplateLoadError("Your template doesn't exist!!!"))